A blockchain-based game system where players can mint sword NFTs and import/export them between the game world and their wallet.
This project consists of two main smart contracts:
Sword
: An ERC721 NFT contract for minting and managing sword tokensWorld
: A game world contract that can hold NFTs on behalf of players
- Node.js v18+
- npm/yarn
- A
.env
file with:SEPOLIA_URL=your_sepolia_rpc_url PRIVATE_KEY=your_wallet_private_key
npm install
npx hardhat test
The contracts are deployed using Hardhat Ignition modules. To deploy:
npx hardhat ignition deploy ./ignition/modules/SwordModule.ts
npx hardhat ignition deploy ./ignition/modules/WorldModule.ts
Several scripts are provided to interact with the deployed contracts:
npx hardhat run scripts/checkSwords.ts
npx hardhat run scripts/importSword.ts
npx hardhat run scripts/exportSword.ts
- Sword: 0xb17ef91a01F269229296b42Fd1d82768443fAD18
- World: 0x266B0D35AF7dc889E9bE144ce41EB08568421803
The test suite covers:
- Minting new sword NFTs
- Transferring ownership
- Importing/exporting between wallet and game world
- Authorization checks
Run tests with:
npx hardhat test
The project uses:
- Hardhat for development environment and testing
- OpenZeppelin for NFT implementation
- TypeScript for deployment scripts and tests
- Hardhat Ignition for deployment management
ISC
The system currently works as follows:
- Users can mint sword NFTs
- To move a sword into a game world:
- Owner must first approve the World contract to handle their NFT
- Owner then calls
importItem
on the World contract
- To retrieve a sword from a game world:
- Original owner calls
exportItem
on the World contract - NFT is transferred back to the owner
- Original owner calls
The main limitation is the approval workflow:
- Each World contract requires separate approval for NFT transfers
- For N different worlds, a user needs to make N separate approval transactions
- This becomes costly and cumbersome when:
- Moving items between multiple worlds
- Implementing cross-game compatibility
- Creating new game worlds that want to accept existing swords
We're looking for innovative solutions to improve the NFT transfer workflow. Some areas to consider:
-
Universal Approval System
- How can we implement a single approval that works across multiple world contracts?
- What security considerations need to be addressed?
-
Smart Contract Architecture
- Could a registry or proxy pattern help?
- How to maintain individual world autonomy while reducing approval friction?
-
Gas Optimization
- How can we minimize the number of transactions needed?
- What patterns could reduce gas costs for users?
- Fork the repository
- Create a new branch for your feature
- Implement your solution
- Add tests and documentation
- Submit a Pull Request with:
- Detailed description of your approach
- Gas cost analysis
- Security considerations
- Any tradeoffs made
We welcome all creative solutions! Please ensure your PR includes:
- Clean, well-documented code
- Comprehensive test coverage
- Gas optimization analysis
- Security considerations
Join the discussion in our Issues section!