Skip to content

About

A minimal full-stack Web3 DApp with modern UI - 一个具有现代UI的最小化全栈Web3去中心化应用

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

🚀 Hello Storage DApp - Complete Web3 Development Tutorial

🚀 Hello Storage DApp - 完整的Web3开发教程

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开发过程!

📁 Project Structure / 项目结构

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 / 本文件

🎯 What This DApp Does / 这个DApp的功能

  • 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 / 钱包连接、数字存储、双语界面

🛠️ Prerequisites / 先决条件

Before starting, make sure you have / 开始之前,请确保您拥有:

  1. Node.js (v16 or higher) - Download here / 下载地址
  2. MetaMask browser extension - Install here / 安装地址
  3. Sepolia testnet ETH - Get from Sepolia Faucet / 从Sepolia水龙头获取
  4. Infura/Alchemy account (for RPC endpoint) / Infura/Alchemy账户(用于RPC端点)

🚀 Complete Setup & Deployment Workflow / 完整设置和部署工作流程

Step 1: Setup Environment Variables / 步骤1:设置环境变量

  1. Navigate to the simple-storage folder / 导航到simple-storage文件夹:

    cd simple-storage
  2. Copy the environment template / 复制环境变量模板:

    cp env.example .env
  3. Edit .env file 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 / 如何获取这些值:

    • PRIVATE_KEY: Export from MetaMask (Account Details → Export Private Key) / 从MetaMask导出(账户详情→导出私钥)
    • SEPOLIA_URL: Create a project on Infura or Alchemy / 在Infura或Alchemy上创建项目

Step 2: Install Backend Dependencies / 步骤2:安装后端依赖

cd simple-storage
npm install

Step 3: Compile Smart Contract / 步骤3:编译智能合约

npm run compile

Expected output / 预期输出:

Compiled 1 Solidity file successfully

Step 4: Deploy to Sepolia Testnet / 步骤4:部署到Sepolia测试网

npm run deploy:sepolia

Expected 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!

⚠️ IMPORTANT: Copy the contract address from the output - you'll need it for the frontend! ⚠️ 重要:从输出中复制合约地址 - 您将需要它用于前端!

Step 5: Update Frontend Contract Address / 步骤5:更新前端合约地址

  1. Navigate to the frontend folder / 导航到前端文件夹:

    cd ../simple-storage-frontend
  2. Open pages/index.tsx and 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

Step 6: Install Frontend Dependencies / 步骤6:安装前端依赖

npm install

Step 7: Start Frontend Development Server / 步骤7:启动前端开发服务器

npm run dev

The DApp will be available at: http://localhost:7897 DApp将在以下地址可用:http://localhost:7897

🎮 How to Use the DApp / 如何使用DApp

  1. Open the DApp / 打开DApp: Navigate to http://localhost:7897
  2. Connect Wallet / 连接钱包: Click "Connect MetaMask" and approve the connection / 点击"Connect MetaMask"并批准连接
  3. Switch to Sepolia / 切换到Sepolia: If not already on Sepolia, click "Switch to Sepolia" / 如果不在Sepolia上,点击"Switch to Sepolia"
  4. Store a Number / 存储数字:
    • Enter a number in the input field / 在输入字段中输入数字
    • Click "Set Number" / 点击"Set Number"
    • Confirm the transaction in MetaMask / 在MetaMask中确认交易
  5. View Stored Number / 查看存储的数字: Click "Get Number" to see the current stored number / 点击"Get Number"查看当前存储的数字

🎨 New Features / 新功能

Modern UI with Tailwind CSS / 使用Tailwind CSS的现代UI

  • Beautiful gradient background / 美丽的渐变背景
  • Centered card layout / 居中卡片布局
  • Smooth animations and transitions / 流畅的动画和过渡
  • Responsive design / 响应式设计

Enhanced Wallet Integration / 增强的钱包集成

  • wagmi hooks for better wallet management / wagmi钩子用于更好的钱包管理
  • Automatic network detection / 自动网络检测
  • Improved error handling / 改进的错误处理

Bilingual Interface / 双语界面

  • English and Chinese support / 英文和中文支持
  • Clear status messages in both languages / 两种语言的清晰状态消息

🔧 Troubleshooting / 故障排除

Common Issues / 常见问题:

  1. "MetaMask is not installed" / "MetaMask未安装"

    • Install MetaMask browser extension / 安装MetaMask浏览器扩展
    • Refresh the page / 刷新页面
  2. "Please switch to Sepolia testnet" / "请切换到Sepolia测试网"

    • Click "Switch to Sepolia" button / 点击"Switch to Sepolia"按钮
    • Or manually switch in MetaMask / 或在MetaMask中手动切换
  3. "Insufficient funds" / "资金不足"

  4. "Contract not deployed" / "合约未部署"

    • Make sure you updated the CONTRACT_ADDRESS in the frontend / 确保您在前端更新了CONTRACT_ADDRESS
    • Verify the contract was deployed successfully / 验证合约是否成功部署
  5. "RPC Error" / "RPC错误"

    • Check your Infura/Alchemy URL in .env / 检查.env中的Infura/Alchemy URL
    • Make sure you have the correct project ID / 确保您有正确的项目ID

Useful Commands / 有用命令:

# 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_ADDRESS

📚 What You've Learned / 您学到的知识

After completing this tutorial, you understand / 完成本教程后,您了解:

  1. Smart Contract Development / 智能合约开发: Writing, compiling, and deploying Solidity contracts / 编写、编译和部署Solidity合约
  2. Hardhat Framework / Hardhat框架: Project setup, configuration, and deployment scripts / 项目设置、配置和部署脚本
  3. Modern Frontend Integration / 现代前端集成: Connecting web apps to blockchain using wagmi + ethers.js / 使用wagmi + ethers.js将Web应用连接到区块链
  4. Tailwind CSS / Tailwind CSS: Creating beautiful, responsive UIs / 创建美观、响应式的UI
  5. Wallet Integration / 钱包集成: MetaMask connection and transaction handling / MetaMask连接和交易处理
  6. Testnet Deployment / 测试网部署: Deploying and interacting with contracts on Sepolia / 在Sepolia上部署合约并与之交互
  7. Full-Stack Web3 / 全栈Web3: Complete workflow from backend to frontend / 从后端到前端的完整工作流程

🔄 Next Steps / 下一步

Now that you have a working DApp, you can / 现在您有了一个可工作的DApp,您可以:

  1. Add Features / 添加功能: Implement more complex storage (arrays, structs, mappings) / 实现更复杂的存储(数组、结构体、映射)
  2. Improve UI / 改进UI: Add more Tailwind components, animations / 添加更多Tailwind组件、动画
  3. Add Tests / 添加测试: Write unit tests for your smart contract / 为您的智能合约编写单元测试
  4. Deploy to Mainnet / 部署到主网: Deploy to Ethereum mainnet (requires real ETH) / 部署到以太坊主网(需要真实的ETH)
  5. Add More Networks / 添加更多网络: Support other testnets or Layer 2 solutions / 支持其他测试网或Layer 2解决方案

🆘 Getting Help / 获取帮助

If you encounter issues / 如果您遇到问题:

  1. Check the console for error messages / 检查控制台中的错误消息
  2. Verify all environment variables are set correctly / 验证所有环境变量是否正确设置
  3. Ensure you have test ETH on Sepolia / 确保您在Sepolia上有测试ETH
  4. Make sure MetaMask is connected to the right network / 确保MetaMask连接到正确的网络

🎉 Congratulations! / 恭喜!

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! 🚀 / 编码愉快!🚀

About

A minimal full-stack Web3 DApp with modern UI - 一个具有现代UI的最小化全栈Web3去中心化应用

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages