This is a 100% decentralized blockchain red packet application. Users can connect their wallets, set an amount and quantity to send red packets, and then share a link for others to claim. All data and operations are based on the blockchain, completely eliminating the need for centralized servers, making the entire process secure, transparent, and traceable.

If you’re interested, you can check out my code on GitHub: redpacket‑dapp

Feature Highlights

Tech Stack

Quick Start

# 1. Install project dependencies
npm install
cd react-dapp && npm install && cd ..

# 2. Start local blockchain node
npm run node

# 3. Compile smart contracts
npx hardhat compile

# 4. Deploy smart contracts
npm run deploy

# 5. Start frontend
npm run frontend

Directory Structure

redpacket-web3/
├─ contracts/                # Solidity smart contracts
│  └─ RedPacket.sol
├─ react-dapp/               # React + Vite frontend
│  ├─ src/
│  │  ├─ components/         # Common components (wallet button, create form, etc.)
│  │  ├─ config/             # ABI, contract address configuration
│  │  ├─ hooks/              # Custom hooks (useWallet)
│  │  ├─ pages/              # Pages (Home, ClaimPacket)
│  │  ├─ styles/             # Global styles
│  │  ├─ utils/              # Web3 utility functions
│  │  └─ App.tsx             # Routing and layout
│  ├─ .env.example           # Frontend environment variable instructions
│  └─ package.json
├─ scripts/
│  └─ deploy.js              # Hardhat deployment script (automatically writes to frontend config)
├─ hardhat.config.js
└─ package.json              # Root scripts (Hardhat + frontend one-click start)

Usage Guide

Create a Red Packet

  1. Open the frontend and click “Connect Wallet” in the top right corner.
  2. Fill in the total red packet amount and number of shares; the application will randomly split the amount on the frontend.
  3. Submit and confirm the transaction in MetaMask, then wait for block confirmation.
  4. Upon success, copy the system-generated claim link and share it with friends.

Claim a Red Packet

  1. Open the shared link (URL contains /claim/{packetId}).
  2. Connect your wallet first, then click “Claim”.
  3. After signing and confirming, wait for the block to be mined. The page will display the result and remaining shares.

Environment Variables

Smart Contract (RedPacket.sol)

Core methods:

Hardhat node or BSC testnet can reuse the above interfaces. The deployment script will synchronize the latest address to the frontend. If redeploying, please rerun npm run deploy.

Deploy USDC (USDC.sol)

Networks

Local Hardhat

BSC Testnet

FAQ

Happy red packet grabbing! 🧨

⚠️ Reminder: This project is for functionality and feasibility testing only, has not been deployed to testnet or mainnet, and has not undergone complete security testing. Please do not use it for actual asset operations. Risks arising from its use are to be borne by yourself.

image

image

image

image

image

Copyright Notice

Author: MoeJue

Link: https://ja.moejue.cn/en/posts/303/

License: クリエイティブ・コモンズ表示-非営利-継承4.0国際ライセンス

この作品は、クリエイティブ・コモンズ表示-非営利-継承4.0国際ライセンスに基づいてライセンスされています。

Start searching

Enter keywords to search articles

↑↓
ESC
⌘K Shortcut