Skip to content

ewdlop/boilerplate-javascript-react-solidity-dapp

Repository files navigation

Advanced Token DApp / 高级代币去中心化应用

A comprehensive decentralized application (DApp) for ERC-20 token management with advanced features, built with React, Solidity, and Web3.js.

一个功能全面的 ERC-20 代币管理去中心化应用,具有高级功能,基于 React、Solidity 和 Web3.js 构建。

🚀 Features / 功能特性

Core Features / 核心功能

  • Smart Contract Management / 智能合约管理: Deploy and manage ERC-20 token contracts
  • Token Balance Checking / 代币余额查询: Real-time balance checking for any Ethereum address
  • Token Transfer / 代币转账: Secure token transfers with transaction tracking
  • Account Management / 账户管理: Comprehensive Ganache account overview with ETH and token balances

Advanced Features / 高级功能

  • Bulk Operations / 批量操作: Batch token transfers and airdrops
  • Token Approval System / 代币授权系统: ERC-20 allowance management and approval tracking
  • Transaction History / 交易历史: Complete transaction logging with export functionality
  • Multi-language Support / 多语言支持: Full English and Simplified Chinese interface

Developer Features / 开发者功能

  • Local Development / 本地开发: Integrated Ganache blockchain environment
  • Real-time Updates / 实时更新: Automatic balance and transaction updates
  • Error Handling / 错误处理: Comprehensive error handling and user feedback
  • Modern UI/UX / 现代化界面: Beautiful Ant Design interface with responsive design

🛠 Technology Stack / 技术栈

  • Frontend / 前端: React 18, Vite, Redux Toolkit, RTK Query, Ant Design
  • Backend / 后端: Node.js, Express.js, Web3.js, CORS
  • Blockchain / 区块链: Solidity, Ganache (local Ethereum blockchain)
  • Development Tools / 开发工具: Concurrently, dotenv

📋 Prerequisites / 前置要求

  • Node.js (v16 or higher / v16 或更高版本)
  • npm or yarn
  • Git
  • 4GB+ RAM for Ganache / 4GB+ 内存用于 Ganache

🚀 Quick Start / 快速开始

  1. Clone the repository / 克隆仓库

    git clone <repository-url>
    cd DApp
  2. Install dependencies / 安装依赖

    npm install
  3. Start the development environment / 启动开发环境

    npm run dev

    This will start:

    • 🔗 Ganache blockchain on http://localhost:8545
    • 🖥️ Express server on http://localhost:3000
    • 🌐 React frontend on http://localhost:5173

    这将启动:

    • 🔗 Ganache 区块链在 http://localhost:8545
    • 🖥️ Express 服务器在 http://localhost:3000
    • 🌐 React 前端在 http://localhost:5173

📖 Usage Guide / 使用指南

1. Contract Management / 合约管理

  • Navigate to the Contract tab / 导航到合约选项卡
  • Deploy your ERC-20 token contract / 部署您的 ERC-20 代币合约
  • View contract details and specifications / 查看合约详情和规格

2. Account Management / 账户管理

  • Accounts tab shows all Ganache accounts / 账户选项卡显示所有 Ganache 账户
  • View ETH and token balances / 查看 ETH 和代币余额
  • Copy addresses and select accounts / 复制地址并选择账户

3. Token Operations / 代币操作

  • Overview tab for basic balance checking and transfers / 概览选项卡用于基本余额查询和转账
  • Real-time balance updates after transactions / 交易后实时余额更新

4. Bulk Operations / 批量操作

  • Bulk Ops tab for batch transfers / 批量操作选项卡用于批量转账
  • Add recipients individually or import in bulk / 单独添加接收者或批量导入
  • Execute multiple transfers with progress tracking / 执行多个转账并跟踪进度

5. Token Approvals / 代币授权

  • Approvals tab for ERC-20 allowance management / 授权选项卡用于 ERC-20 授权额度管理
  • Approve spending limits for other addresses / 为其他地址批准支出限额
  • Check and revoke existing approvals / 检查和撤销现有授权

6. Transaction History / 交易历史

  • History tab shows all transactions / 历史选项卡显示所有交易
  • Export transaction data / 导出交易数据
  • Filter and search transaction records / 过滤和搜索交易记录

🏗 Project Structure / 项目结构

DApp/
├── contracts/                    # Smart contracts / 智能合约
│   └── SimpleToken.sol          # ERC-20 token contract / ERC-20 代币合约
├── scripts/                     # Deployment scripts / 部署脚本
│   ├── deploy.js               # Contract deployment / 合约部署
│   └── start-ganache.js        # Ganache configuration / Ganache 配置
├── frontend/                    # React frontend / React 前端
│   ├── src/
│   │   ├── components/         # React components / React 组件
│   │   │   ├── TokenBalance.jsx      # Balance checker / 余额查询器
│   │   │   ├── TokenTransfer.jsx     # Transfer interface / 转账界面
│   │   │   ├── ContractDeployment.jsx # Contract management / 合约管理
│   │   │   ├── AccountManager.jsx    # Account overview / 账户概览
│   │   │   ├── BulkOperations.jsx    # Batch operations / 批量操作
│   │   │   ├── TokenApproval.jsx     # Approval management / 授权管理
│   │   │   └── TransactionHistory.jsx # Transaction log / 交易日志
│   │   ├── store/              # Redux store / Redux 存储
│   │   │   └── apiSlice.js     # RTK Query API / RTK Query API
│   │   └── App.jsx             # Main app / 主应用
│   └── package.json
├── server.js                    # Express backend / Express 后端
├── package.json                 # Dependencies / 依赖项
└── README.md                    # Documentation / 文档

🔌 API Endpoints / API 端点

Contract Management / 合约管理

  • POST /deploy - Deploy smart contract / 部署智能合约
  • GET /contract-info - Get contract information / 获取合约信息
  • GET /token-info - Get token details / 获取代币详情
  • GET /total-supply - Get total token supply / 获取代币总供应量

Token Operations / 代币操作

  • GET /balance/:address - Get token balance / 获取代币余额
  • POST /transfer - Transfer tokens / 转账代币
  • POST /approve - Approve token spending / 授权代币支出
  • GET /allowance/:owner/:spender - Check allowance / 检查授权额度

💎 Smart Contract Details / 智能合约详情

Token Specifications / 代币规格

  • Name / 名称: Simple Token
  • Symbol / 符号: STK
  • Decimals / 小数位数: 18
  • Total Supply / 总供应量: 1,000,000 STK
  • Standard / 标准: ERC-20

Contract Features / 合约功能

  • ✅ Standard ERC-20 functions / 标准 ERC-20 功能
  • ✅ Transfer and approval mechanisms / 转账和授权机制
  • ✅ Balance and allowance queries / 余额和授权额度查询
  • ✅ Event emission for transparency / 事件发射以提高透明度

🔧 Development / 开发

Available Scripts / 可用脚本

# Full development environment / 完整开发环境
npm run dev

# Individual services / 单独服务
npm start                    # Backend only / 仅后端
npm run start:ganache       # Ganache only / 仅 Ganache
npm run frontend            # Frontend only / 仅前端

Environment Configuration / 环境配置

Create .env file / 创建 .env 文件:

ETHEREUM_NODE_URL=http://localhost:8545
PORT=3000
NODE_ENV=development

Ganache Configuration / Ganache 配置

  • Network ID: 1337
  • Gas Limit: 10,000,000
  • Gas Price: 20 Gwei
  • Accounts: 10 pre-funded accounts with 1000 ETH each
  • Hardfork: London

🐛 Troubleshooting / 故障排除

Common Issues / 常见问题

  1. Port Conflicts / 端口冲突

    # Kill processes on specific ports / 终止特定端口的进程
    npx kill-port 3000 8545
  2. Contract Deployment Issues / 合约部署问题

    • Ensure Ganache is running / 确保 Ganache 正在运行
    • Check gas limits and balances / 检查 gas 限制和余额
    • Verify network connectivity / 验证网络连接
  3. Transaction Failures / 交易失败

    • Insufficient gas / Gas 不足
    • Invalid addresses / 地址无效
    • Insufficient token balance / 代币余额不足
  4. Frontend Connection Issues / 前端连接问题

    • Check CORS configuration / 检查 CORS 配置
    • Verify API endpoints / 验证 API 端点
    • Ensure backend is running / 确保后端正在运行

Debug Mode / 调试模式

Enable detailed logging / 启用详细日志记录:

DEBUG=* npm run dev

🚀 Future Contract Ideas / 未来合约创意

This section outlines exciting smart contract concepts that could be implemented to extend the DApp's functionality. These ideas range from beginner-friendly to advanced implementations.

本节概述了可以实施以扩展 DApp 功能的令人兴奋的智能合约概念。这些想法从初学者友好到高级实现不等。

🏆 Recommended for Next Implementation / 推荐下一步实现

1. Token Staking & Rewards Contract / 代币质押和奖励合约

// Stake tokens to earn rewards / 质押代币以获得奖励
Features / 功能:
- Multiple staking pools with different APY rates / 不同 APY 利率的多个质押池
- Lock-up periods for higher rewards / 锁定期以获得更高奖励
- Compound interest calculations / 复利计算
- Emergency withdrawal mechanisms / 紧急提取机制

2. Decentralized Voting/DAO Contract / 去中心化投票/DAO 合约

// Governance and community decision making / 治理和社区决策
Features / 功能:
- Proposal creation and voting / 提案创建和投票
- Token-weighted voting power / 代币加权投票权
- Execution of passed proposals / 执行通过的提案
- Treasury management / 财库管理

3. NFT + Lottery Hybrid Contract / NFT + 彩票混合合约

// Gamified NFT experience / 游戏化 NFT 体验
Features / 功能:
- Mint lottery tickets as NFTs / 将彩票作为 NFT 铸造
- Provably fair random number generation / 可证明公平的随机数生成
- Winner announcements and prize distribution / 获奖者公告和奖品分发
- Collectible ticket designs / 可收藏的票据设计

🏦 DeFi Protocol Ideas / DeFi 协议创意

4. Lending & Borrowing Protocol / 借贷协议

// Decentralized finance lending platform / 去中心化金融借贷平台
Features / 功能:
- Collateralized loans / 抵押贷款
- Dynamic interest rate calculations / 动态利率计算
- Liquidation mechanisms / 清算机制
- Credit scoring system / 信用评分系统

5. Decentralized Exchange (DEX) / 去中心化交易所

// Automated Market Maker (AMM) / 自动做市商
Features / 功能:
- Liquidity pools / 流动性池
- Token swapping mechanisms / 代币交换机制
- Liquidity provider rewards / 流动性提供者奖励
- Price oracles integration / 价格预言机集成

6. Token Vesting Contract / 代币归属合约

// Time-locked token distribution / 时间锁定代币分发
Features / 功能:
- Linear and cliff vesting schedules / 线性和悬崖归属时间表
- Team and investor allocations / 团队和投资者分配
- Revocable vesting for employees / 员工可撤销归属
- Milestone-based releases / 基于里程碑的发布

🔒 Security & Utility Contracts / 安全和实用合约

7. Multi-Signature Wallet Contract / 多重签名钱包合约

// Enhanced security for fund management / 增强资金管理安全性
Features / 功能:
- Require multiple signatures for transactions / 交易需要多重签名
- Time-locked transactions / 时间锁定交易
- Emergency recovery mechanisms / 紧急恢复机制
- Role-based access control / 基于角色的访问控制

8. Insurance Protocol / 保险协议

// Decentralized insurance coverage / 去中心化保险覆盖
Features / 功能:
- Smart contract coverage / 智能合约覆盖
- Premium calculations / 保费计算
- Automated claim processing / 自动理赔处理
- Risk assessment pools / 风险评估池

🎮 Gaming & Entertainment / 游戏和娱乐

9. Blockchain Gaming Platform / 区块链游戏平台

// Gaming ecosystem with tokenized rewards / 具有代币化奖励的游戏生态系统
Features / 功能:
- Achievement tokens/badges / 成就代币/徽章
- Leaderboards and tournaments / 排行榜和锦标赛
- In-game asset trading / 游戏内资产交易
- Play-to-earn mechanisms / 边玩边赚机制

10. NFT Marketplace Contract / NFT 市场合约

// Create and trade digital assets / 创建和交易数字资产
Features / 功能:
- Mint custom NFTs with metadata / 使用元数据铸造自定义 NFT
- Auction and fixed-price sales / 拍卖和固定价格销售
- Royalty payments to creators / 向创作者支付版税
- Collection management / 收藏管理

🌍 Real-World Applications / 现实世界应用

11. Supply Chain Tracking / 供应链跟踪

// Product authenticity and lifecycle tracking / 产品真实性和生命周期跟踪
Features / 功能:
- Product lifecycle tracking / 产品生命周期跟踪
- Authenticity verification / 真实性验证
- Quality assurance records / 质量保证记录
- Recall management / 召回管理

12. Carbon Credit Trading / 碳信用交易

// Environmental impact tokenization / 环境影响代币化
Features / 功能:
- Carbon offset tokenization / 碳抵消代币化
- Verification and certification / 验证和认证
- Trading marketplace / 交易市场
- Impact tracking and reporting / 影响跟踪和报告

🎯 Implementation Roadmap / 实施路线图

Phase 1: Learning & Foundation / 第一阶段:学习和基础

  1. Staking Contract - Easy DeFi introduction / 简单的 DeFi 介绍
  2. Voting DAO - Governance concepts / 治理概念
  3. Multi-Sig Wallet - Security practices / 安全实践

Phase 2: Advanced DeFi / 第二阶段:高级 DeFi

  1. Lending Protocol - Complex financial logic / 复杂的金融逻辑
  2. Mini DEX - AMM implementation / AMM 实现
  3. Token Vesting - Time-based mechanics / 基于时间的机制

Phase 3: Innovation & Gaming / 第三阶段:创新和游戏

  1. NFT Marketplace - Digital asset economy / 数字资产经济
  2. Gaming Platform - Tokenized entertainment / 代币化娱乐
  3. Insurance Protocol - Risk management / 风险管理

Phase 4: Real-World Integration / 第四阶段:现实世界集成

  1. Supply Chain - Enterprise applications / 企业应用
  2. Carbon Credits - Environmental impact / 环境影响
  3. Cross-chain Bridge - Interoperability / 互操作性

💡 Development Considerations / 开发考虑因素

Technical Requirements / 技术要求

  • Gas Optimization - Efficient contract design / 高效的合约设计
  • Security Audits - Professional code review / 专业代码审查
  • Testing Coverage - Comprehensive test suites / 全面的测试套件
  • Documentation - Clear implementation guides / 清晰的实施指南

UI/UX Enhancements / UI/UX 增强

  • Interactive Dashboards - Real-time data visualization / 实时数据可视化
  • Mobile Responsiveness - Cross-platform compatibility / 跨平台兼容性
  • User Onboarding - Guided tutorials / 引导教程
  • Accessibility - Inclusive design principles / 包容性设计原则

Integration Features / 集成功能

  • Wallet Connectivity - MetaMask, WalletConnect / MetaMask, WalletConnect
  • Price Feeds - Chainlink oracles / Chainlink 预言机
  • IPFS Storage - Decentralized file storage / 去中心化文件存储
  • Analytics - Transaction and usage metrics / 交易和使用指标

🎨 Community Suggestions / 社区建议

We welcome community input on which contracts to implement next! Consider factors like:

我们欢迎社区对下一步实施哪些合约的意见!考虑以下因素:

  • Learning Value - Educational benefit / 教育价值
  • Market Demand - Real-world utility / 现实世界实用性
  • Technical Challenge - Skill development / 技能发展
  • Innovation Potential - Unique features / 独特功能

Vote for your favorite contract idea or suggest new ones! / 为您最喜欢的合约创意投票或提出新的想法!


🤝 Contributing / 贡献

  1. Fork the repository / 分叉仓库
  2. Create feature branch / 创建功能分支
    git checkout -b feature/amazing-feature
  3. Commit changes / 提交更改
    git commit -m 'Add amazing feature'
  4. Push to branch / 推送到分支
    git push origin feature/amazing-feature
  5. Open Pull Request / 开启拉取请求

📄 License / 许可证

This project is licensed under the MIT License - see the LICENSE file for details.

本项目采用 MIT 许可证 - 详情请参阅 LICENSE 文件。

🙏 Acknowledgments / 致谢

  • Ethereum Foundation for Web3 standards and blockchain infrastructure / 以太坊基金会的 Web3 标准和区块链基础设施
  • OpenZeppelin for secure smart contract patterns and libraries / OpenZeppelin 的安全智能合约模式和库
  • Ant Design for the comprehensive React UI component library that powers our beautiful interface / Ant Design 提供的全面 React UI 组件库,为我们的美观界面提供支持
  • Ganache for local blockchain development and testing environment / Ganache 的本地区块链开发和测试环境
  • React Team for the powerful frontend framework / React 团队提供的强大前端框架
  • Redux Toolkit for efficient state management / Redux Toolkit 的高效状态管理
  • Vite for fast development build tooling / Vite 的快速开发构建工具
  • Web3.js for Ethereum blockchain interaction / Web3.js 的以太坊区块链交互功能

Happy Coding! / 编程愉快! 🚀

About

Token DApp / 代币 DApp

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published