CryptoPets Arena is a blockchain pet battle DApp built with Solidity, Hardhat, Ganache, MetaMask, and ethers.js.
The game uses ERC721 NFTs to represent pets. Players can mint pets, view pet stats, create challenges, accept battles, gain experience, level up, and heal pets. Core game state is stored in the smart contract, while the frontend only sends transactions and reads on-chain data.
| Path | Description |
|---|---|
contracts/CryptoPetsArena.sol |
ERC721 pet NFT contract and battle logic |
scripts/deploy.cjs |
Hardhat deployment script |
frontend/index.html |
Static frontend using ethers.js and MetaMask |
hardhat.config.cjs |
Solidity compiler and Ganache network config |
项目代码原理说明.md |
Code-level explanation for defense/presentation |
- Mint random NFT pets with test ETH.
- Store pet type, level, experience, HP, attack, defense, battle count, and win count on-chain.
- Battle with Fire, Water, and Grass type advantages.
- Create and accept player challenges.
- Automatically update battle count, win count, experience, HP, and level.
- Heal damaged pets with test ETH.
- Install dependencies:
npm install- Start Ganache and make sure it is running at:
http://127.0.0.1:7545
- Compile the contract:
npm run compile- Deploy to Ganache:
npm run deploy- Start the frontend:
npm run start- Open the frontend and connect MetaMask to the same Ganache network.
frontend/contract-address.jsonis generated by the deploy script and is not committed.node_modules, Hardhat artifacts, and cache files are ignored.- The current random number logic is suitable for local experiments. A production deployment should use a verifiable randomness provider such as Chainlink VRF.