A blockchain-powered RPG game where players can generate random items, engage in turn-based combat, and mint their items as NFTs on the blockchain. Built with Next.js, TypeScript, and Solidity.
- Random Item Generation: Generate unique RPG items with pixel art, stats, and special abilities
- Turn-based Combat: Battle against AI enemies using your generated items
- NFT Integration: Mint your favorite items as NFTs on Ethereum and Polygon testnets
- MetaMask Integration: Connect your wallet to interact with the blockchain
- Pixel Art Rendering: Beautiful retro-style pixel art for all items
- Progressive Leveling: Gain experience and level up through combat
- Frontend: Next.js 15, React 19, TypeScript, Tailwind CSS
- Blockchain: Ethereum, Polygon, Solidity, Hardhat
- Web3 Libraries: Ethers.js, Wagmi, Viem
- State Management: Zustand
- Smart Contracts: OpenZeppelin ERC-721
- Node.js 18+ and npm
- MetaMask browser extension
- FREE testnet tokens (no mainnet ETH required!)
git clone <repository-url>
cd blockbound
npm installCreate a .env file in the root directory:
# Ethereum Network Configuration
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/<ALCHEMY_PROJECT>
# Private key for deployment
PRIVATE_KEY=your_private_key_here
# Etherscan API key for contract verification
ETHERSCAN_API_KEY=your_etherscan_api_key_here
# Next.js Configuration
NEXT_PUBLIC_ENVIRONMENT=development
NEXT_PUBLIC_SEPOLIA_CONTRACT_ADDRESS=your_sepolia_contractGet SepoliaETH from these faucets:
- Alchemy Faucet - Requires Alchemy account
Compile the smart contracts:
npm run compileDeploy to Sepolia testnet:
npm run deploy:sepoliaAfter deployment, update the contract address in .env.
npm run devOpen http://localhost:3000 in your browser.
- Connect MetaMask: Click "Connect MetaMask" and approve the connection
- Switch Network: Switch to Sepolia testnet
- Register: Enter a username to create your game profile
- Generate Items: Click "Random Item" to generate unique RPG items
- Battle: Use "Fight!" to engage in turn-based combat with AI enemies
- Mint NFTs: Click "🎨 Mint as NFT" to mint your favorite items as blockchain NFTs
- Level Up: Gain experience through combat to increase your level
The main smart contract (contracts/GameItemNFT.sol) is an ERC-721 NFT contract that stores:
- Item Metadata: Name, description, rarity, type, level
- Item Stats: Attack, defense, speed, health, magic, crit chance
- Pixel Art Data: JSON representation of the item's pixel art
- Player Inventory: Mapping of player addresses to their owned NFTs
Key functions:
mintItem(): Mint a new item NFTgetPlayerItems(): Get all NFTs owned by a playergetItemDetails(): Get detailed information about an NFT
- 5 Rarity Levels: Common, Uncommon, Rare, Epic, Legendary
- 4 Item Types: Weapon, Armor, Accessory, Consumable
- 6 Core Stats: Attack, Defense, Speed, Health, Magic, Crit Chance
- Procedural Pixel Art: Unique 8x8 pixel art generated for each item
- Turn-based: Player and enemy alternate turns
- Stat-based Damage: Damage calculated from attack vs defense
- Critical Hits: Based on crit chance stat
- Special Attacks: Unique abilities for certain items
- Experience Gain: Level up through successful battles
- On-chain Storage: All item data stored directly on the blockchain
- Metadata Standard: ERC-721 compliant metadata with OpenSea compatibility
- Gas Optimization: Efficient contract design to minimize transaction costs
- Multi-chain Support: Deploy on Ethereum or Polygon for different cost profiles
blockbound/
├── app/ # Next.js app directory
│ ├── components/ # React components
│ ├── lib/ # Web3 configuration
│ ├── services/ # Web3 service layer
│ ├── store/ # Zustand state management
│ └── utils/ # Utility functions
├── contracts/ # Solidity smart contracts
├── scripts/ # Deployment scripts
├── types/ # TypeScript type definitions
└── public/ # Static assets
npm run dev- Start development servernpm run build- Build for productionnpm run compile- Compile smart contractsnpm run deploy:sepolia- Deploy to Sepolia testnet
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly on testnet
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
Note: This is a demo application for educational purposes. Always use test networks and never share private keys or seed phrases. For production use, implement additional security measures and thorough testing.