A minimal full-stack Web3 DApp with modern UI that demonstrates the complete workflow from smart contract development to frontend interaction. Perfect for learning the entire Web3 development process in one day! 一个具有现代UI的最小化全栈Web3去中心化应用,展示了从智能合约开发到前端交互的完整工作流程。非常适合一天内学习整个Web3开发过程!
Hello Storage DApp/
├── simple-storage/ # Hardhat backend project / Hardhat后端项目
│ ├── contracts/
│ │ └── SimpleStorage.sol # Smart contract / 智能合约
│ ├── scripts/
│ │ └── deploy.js # Deployment script / 部署脚本
│ ├── hardhat.config.js # Hardhat configuration / Hardhat配置
│ ├── package.json # Backend dependencies / 后端依赖
│ └── env.example # Environment variables template / 环境变量模板
│
├── simple-storage-frontend/ # Next.js frontend project / Next.js前端项目
│ ├── pages/
│ │ ├── index.tsx # Main DApp interface / 主DApp界面
│ │ └── _app.tsx # Next.js app wrapper / Next.js应用包装器
│ ├── lib/
│ │ └── wagmi.ts # Wagmi configuration / Wagmi配置
│ ├── abi/
│ │ └── SimpleStorage.json # Contract ABI / 合约ABI
│ ├── styles/
│ │ └── globals.css # Tailwind CSS styling / Tailwind CSS样式
│ ├── package.json # Frontend dependencies / 前端依赖
│ ├── next.config.js # Next.js configuration / Next.js配置
│ ├── tailwind.config.js # Tailwind configuration / Tailwind配置
│ ├── postcss.config.js # PostCSS configuration / PostCSS配置
│ └── tsconfig.json # TypeScript configuration / TypeScript配置
│
└── README.md # This file / 本文件
- Smart Contract / 智能合约: Stores and retrieves a number on the blockchain / 在区块链上存储和检索数字
- Frontend / 前端: Modern UI with Tailwind CSS, wagmi integration / 具有Tailwind CSS和wagmi集成的现代UI
- Network / 网络: Deploys to Sepolia testnet (safe for testing) / 部署到Sepolia测试网(安全测试)
- Features / 功能: Wallet connection, number storage, bilingual interface / 钱包连接、数字存储、双语界面
Before starting, make sure you have / 开始之前,请确保您拥有:
- Node.js (v16 or higher) - Download here / 下载地址
- MetaMask browser extension - Install here / 安装地址
- Sepolia testnet ETH - Get from Sepolia Faucet / 从Sepolia水龙头获取
- Infura/Alchemy account (for RPC endpoint) / Infura/Alchemy账户(用于RPC端点)
-
Navigate to the
simple-storagefolder / 导航到simple-storage文件夹:cd simple-storage -
Copy the environment template / 复制环境变量模板:
cp env.example .env
-
Edit
.envfile with your values / 使用您的值编辑.env文件:# Your private key (without 0x prefix) / 您的私钥(不带0x前缀) PRIVATE_KEY=your_private_key_here # Infura or Alchemy URL for Sepolia testnet / Sepolia测试网的Infura或Alchemy URL SEPOLIA_URL=https://sepolia.infura.io/v3/your_infura_project_id
How to get these values / 如何获取这些值:
cd simple-storage
npm installnpm run compileExpected output / 预期输出:
Compiled 1 Solidity file successfully
npm run deploy:sepoliaExpected output / 预期输出:
Starting deployment...
Deploying SimpleStorage...
✅ SimpleStorage deployed to: 0x1234...5678
📝 Contract address for frontend: 0x1234...5678
Storing initial value of 42...
✅ Initial value stored and verified: 42
🎉 Deployment complete!
-
Navigate to the frontend folder / 导航到前端文件夹:
cd ../simple-storage-frontend -
Open
pages/index.tsxand replace this line / 打开pages/index.tsx并替换这一行:const CONTRACT_ADDRESS = 'YOUR_CONTRACT_ADDRESS_HERE';
With your deployed contract address / 使用您部署的合约地址:
const CONTRACT_ADDRESS = '0x1234...5678'; // Your actual contract address
npm installnpm run devThe DApp will be available at: http://localhost:7897 DApp将在以下地址可用:http://localhost:7897
- Open the DApp / 打开DApp: Navigate to http://localhost:7897
- Connect Wallet / 连接钱包: Click "Connect MetaMask" and approve the connection / 点击"Connect MetaMask"并批准连接
- Switch to Sepolia / 切换到Sepolia: If not already on Sepolia, click "Switch to Sepolia" / 如果不在Sepolia上,点击"Switch to Sepolia"
- Store a Number / 存储数字:
- Enter a number in the input field / 在输入字段中输入数字
- Click "Set Number" / 点击"Set Number"
- Confirm the transaction in MetaMask / 在MetaMask中确认交易
- View Stored Number / 查看存储的数字: Click "Get Number" to see the current stored number / 点击"Get Number"查看当前存储的数字
- Beautiful gradient background / 美丽的渐变背景
- Centered card layout / 居中卡片布局
- Smooth animations and transitions / 流畅的动画和过渡
- Responsive design / 响应式设计
- wagmi hooks for better wallet management / wagmi钩子用于更好的钱包管理
- Automatic network detection / 自动网络检测
- Improved error handling / 改进的错误处理
- English and Chinese support / 英文和中文支持
- Clear status messages in both languages / 两种语言的清晰状态消息
-
"MetaMask is not installed" / "MetaMask未安装"
- Install MetaMask browser extension / 安装MetaMask浏览器扩展
- Refresh the page / 刷新页面
-
"Please switch to Sepolia testnet" / "请切换到Sepolia测试网"
- Click "Switch to Sepolia" button / 点击"Switch to Sepolia"按钮
- Or manually switch in MetaMask / 或在MetaMask中手动切换
-
"Insufficient funds" / "资金不足"
- Get test ETH from Sepolia Faucet / 从Sepolia水龙头获取测试ETH
-
"Contract not deployed" / "合约未部署"
- Make sure you updated the CONTRACT_ADDRESS in the frontend / 确保您在前端更新了CONTRACT_ADDRESS
- Verify the contract was deployed successfully / 验证合约是否成功部署
-
"RPC Error" / "RPC错误"
- Check your Infura/Alchemy URL in
.env/ 检查.env中的Infura/Alchemy URL - Make sure you have the correct project ID / 确保您有正确的项目ID
- Check your Infura/Alchemy URL in
# Check if everything is installed correctly / 检查是否正确安装了所有内容
node --version
npm --version
# Recompile contract after changes / 更改后重新编译合约
cd simple-storage
npm run compile
# Deploy to local Hardhat network (for testing) / 部署到本地Hardhat网络(用于测试)
cd simple-storage
npx hardhat node # Terminal 1 / 终端1
npm run deploy:local # Terminal 2 / 终端2
# Check contract on Etherscan / 在Etherscan上检查合约
# Visit: https://sepolia.etherscan.io/address/YOUR_CONTRACT_ADDRESS
# 访问:https://sepolia.etherscan.io/address/YOUR_CONTRACT_ADDRESSAfter completing this tutorial, you understand / 完成本教程后,您了解:
- Smart Contract Development / 智能合约开发: Writing, compiling, and deploying Solidity contracts / 编写、编译和部署Solidity合约
- Hardhat Framework / Hardhat框架: Project setup, configuration, and deployment scripts / 项目设置、配置和部署脚本
- Modern Frontend Integration / 现代前端集成: Connecting web apps to blockchain using wagmi + ethers.js / 使用wagmi + ethers.js将Web应用连接到区块链
- Tailwind CSS / Tailwind CSS: Creating beautiful, responsive UIs / 创建美观、响应式的UI
- Wallet Integration / 钱包集成: MetaMask connection and transaction handling / MetaMask连接和交易处理
- Testnet Deployment / 测试网部署: Deploying and interacting with contracts on Sepolia / 在Sepolia上部署合约并与之交互
- Full-Stack Web3 / 全栈Web3: Complete workflow from backend to frontend / 从后端到前端的完整工作流程
Now that you have a working DApp, you can / 现在您有了一个可工作的DApp,您可以:
- Add Features / 添加功能: Implement more complex storage (arrays, structs, mappings) / 实现更复杂的存储(数组、结构体、映射)
- Improve UI / 改进UI: Add more Tailwind components, animations / 添加更多Tailwind组件、动画
- Add Tests / 添加测试: Write unit tests for your smart contract / 为您的智能合约编写单元测试
- Deploy to Mainnet / 部署到主网: Deploy to Ethereum mainnet (requires real ETH) / 部署到以太坊主网(需要真实的ETH)
- Add More Networks / 添加更多网络: Support other testnets or Layer 2 solutions / 支持其他测试网或Layer 2解决方案
If you encounter issues / 如果您遇到问题:
- Check the console for error messages / 检查控制台中的错误消息
- Verify all environment variables are set correctly / 验证所有环境变量是否正确设置
- Ensure you have test ETH on Sepolia / 确保您在Sepolia上有测试ETH
- Make sure MetaMask is connected to the right network / 确保MetaMask连接到正确的网络
You've successfully built and deployed a complete Web3 DApp with modern UI! This foundation will help you build more complex decentralized applications in the future. 您已成功构建并部署了一个具有现代UI的完整Web3去中心化应用!这个基础将帮助您在未来构建更复杂的去中心化应用程序。
Happy coding! 🚀 / 编码愉快!🚀