A comprehensive Solidity smart contract project featuring a decentralized betting platform and RPG character sheet management system. Built with Hardhat framework and OpenZeppelin contracts.
This project contains three main smart contracts:
- CharacterSheetToken.sol - An ERC721 NFT contract that combines character management with tokenization, allowing characters to be minted as tradeable NFTs
- Bet.sol - A decentralized betting platform with support for binary outcomes, creator fees, and Merkle tree-based winner verification
- CharacterSheet.sol - An RPG character sheet system for managing D&D-style characters with ability scores and progression
- Node.js (v16 or higher)
- npm or yarn package manager
-
Install dependencies
npm install
-
Compile contracts
npx hardhat compile
-
Run tests
npx hardhat test
MySmartContract/
├── contracts/
│ ├── Bet.sol # Decentralized betting platform
│ ├── CharacterSheet.sol # RPG character management
│ └── CharacterSheetToken.sol # ERC721 NFT character tokens
├── test/
│ ├── Bet.js # Bet contract tests
│ ├── CharacterSheet.js # CharacterSheet contract tests
│ └── CharacterSheetToken.js # CharacterSheetToken contract tests
├── hardhat.config.js # Hardhat configuration
└── package.json # Dependencies and scripts
Features:
- ERC721 NFT implementation for character tokenization
- Inherits from CharacterSheet.sol for full character management functionality
- Mint characters as tradeable NFTs
- Update character stats (only by token owner)
- Metadata URI support for off-chain character data
- Ownership-based access control for character updates
Key Functions:
mintCharacter()- Create and mint a new character as an NFTupdateCharacter()- Update character ability scores (owner only)getTokenCharacter()- Retrieve character data for a specific tokenownerOf()- Get the current owner of a character tokentransferFrom()- Transfer character ownership (inherited from ERC721)
Integration:
- Extends CharacterSheet.sol functionality with NFT capabilities
- Characters can be traded, sold, or transferred like any ERC721 token
- Maintains all original character management features while adding tokenization
Features:
- Create betting rounds with binary outcomes (X vs Y)
- Support for creator fees (configurable percentage)
- Merkle tree-based winner verification
- Automatic pool distribution to winners
- Round state management (active, cancelled, completed)
Key Functions:
createBetRound()- Create a new betting roundplaceBet()- Place a bet on outcome X or YendBetRound()- End a betting round and set the outcomeclaimWin()- Claim winnings using Merkle proofclaimCreatorFee()- Claim creator fees (WIP)
Features:
- Create and manage D&D-style character sheets
- Support for 16 different race/class combinations
- Track ability scores (STR, DEX, CON, INT, WIS, CHA)
- Character progression and level tracking
- Historical ability score changes
Key Functions:
createCharacter()- Create a new characterupdateAbilityScores()- Update character statsgetCharacter()- Retrieve character informationgetAbilityScoresHistory()- View character progression
Run the complete test suite:
npx hardhat testRun specific test files:
npx hardhat test test/Bet.js
npx hardhat test test/CharacterSheet.js
npx hardhat test test/CharacterSheetToken.jsCore Dependencies:
@openzeppelin/contracts- Secure smart contract librariesethers- Ethereum library for interacting with smart contracts@prb/math- Fixed-point arithmetic library
Development Dependencies:
hardhat- Ethereum development environment@nomicfoundation/hardhat-toolbox- Hardhat plugins and tools
- Contracts use OpenZeppelin's battle-tested libraries
- Comprehensive test coverage for all functions
- Access control modifiers for sensitive operations
- Merkle tree implementation for efficient winner verification
This project is licensed under the MIT License.