Skip to content

Repository files navigation

CryptoPets Arena

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.

Project Structure

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

Main Features

  • 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.

Run Locally

  1. Install dependencies:
npm install
  1. Start Ganache and make sure it is running at:
http://127.0.0.1:7545
  1. Compile the contract:
npm run compile
  1. Deploy to Ganache:
npm run deploy
  1. Start the frontend:
npm run start
  1. Open the frontend and connect MetaMask to the same Ganache network.

Notes

  • frontend/contract-address.json is 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages