Skip to content

onlymimizi/LearnBlockChain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

全栈区块链项目

这是一个完整的全栈区块链应用,包含 React 前端、Go 后端和 Solidity 智能合约。

项目结构

LearnBlockChain/
├── frontend/          # React + Vite + TypeScript 前端
├── backend/           # Go REST API 后端
├── contracts/         # Solidity + Hardhat 智能合约
└── README.md

功能特性

  • 用户注册/登录系统(JWT 认证)
  • MetaMask 钱包连接
  • NFT 铸造功能
  • 积分系统
  • 用户资料管理
  • 响应式 Dashboard

快速启动

1. 启动智能合约(本地网络)

cd contracts
npm install
npx hardhat node
# 新开一个终端
npx hardhat run scripts/deploy.js --network localhost

2. 启动后端服务

cd backend
go mod init backend
go mod tidy
go run main.go

后端将在 http://localhost:8080 启动

3. 启动前端

cd frontend
npm install
npm run dev

前端将在 http://localhost:5173 启动

API 接口

  • POST /api/register - 用户注册
  • POST /api/login - 用户登录
  • GET /api/user - 获取用户信息(需要 JWT)
  • PUT /api/user - 更新用户资料(需要 JWT)

智能合约

  • FishingNFT (FNT): ERC-721 NFT 合约
  • 积分系统: 基于地址的积分管理
  • 主要方法:
    • mintNFT(address to) - 铸造 NFT
    • addPoints(address to, uint256 amount) - 增加积分
    • getPoints(address user) - 查询积分余额

部署说明

前端部署到 Vercel

  1. 构建前端:cd frontend && npm run build
  2. dist 文件夹部署到 Vercel

合约部署到 Sepolia 测试网

  1. 配置 .env 文件(参考 contracts/.env.example
  2. 运行:npx hardhat run scripts/deploy.js --network sepolia

注意事项

  • 确保安装了 MetaMask 浏览器扩展
  • 本地测试时需要将 Hardhat 网络添加到 MetaMask
  • 后端使用 SQLite 数据库,首次运行会自动创建
  • 前端默认连接本地合约,部署时需要更新合约地址

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors