This is a Proof of Concept (POC) cross-chain game that can be deployed on any EVM chain.
- Overview
- Smart Contracts
- Rewards
- Screenshots
- Tech Stack
- Features
- Lessons Learned
- Run Locally
- Environment Variables
- Acknowledgements
- Feedback
- Future Plans
- License
Players can enjoy the game on any blockchain where it is deployed. The cross-play feature allows a player on Chain A, who doesn't have enough tokens, to request a play token from Chain B, provided they have previously bought or received a free play token that hasn't expired. This cross-chain communication is facilitated through CCIP (Cross-Chain Interoperability Protocol), and each token is issued using the Sign protocol. Prizes are awarded randomly to users, utilizing Chainlink VRF (Verifiable Random Function) to ensure fairness. The game interacts with various smart contracts illustrated by the diagram below.
This contract is responsible for granting admin access to any contract that the Game Contract interacts with. This is necessary to ensure that only authorized entities are allowed to mint or control any admin functions defined in any smart contract. The caveat to this approach is that it centralizes control, which is acceptable in this instance since it's just a Proof of Concept (POC).
This contract routes any interactions with external contracts such as:
- Game Attestation Contract
- Chainlink CCIP
- NFT Contract
- Token Contract
- Stream Creator
The game contract is the heart of the entire system. Players have three ways to play the game:
- Free Play: Redeem a free play token valid for three days.
- Paid Play: Purchase a play token valid for seven days. Each play token costs a defined number of units of the PlayToken.
- Cross Play: Use a token from another chain to play, provided a token was purchased or claimed on that chain. The cross chain communication is facilliated by chainlinks CCIP infrustructure where a player on chain A sends a message to chain b the exact implementation can be found here:
- Send message Chain A: https://github.com/Brianspha/chainlink_game/blob/main/packages/contracts/src/game/Game.sol#L249
- Recieve Message from Chain A: https://github.com/Brianspha/chainlink_game/blob/main/packages/contracts/src/game/Game.sol#L364
This works vice versa aswell
The NFT contract is used to reward users who have collected in-game items.
The Token contract is used to reward users who have collected in-game items and to define the PlayToken used to play the game.
This contract issues Play Tokens with a validity timeframe. The Sign Protocol, an omni-chain attestation protocol, enables users to freely attest and verify any information on-chain, ensuring the authenticity of PlayTokens.
These contracts facilitate the requesting of random numbers. They are modified to work locally for better testing without needing to fork existing implementations.
This contract distributes rewards to users who have won by playing the game. It interacts with the Sablier Protocol, a token distribution protocol designed for by-the-second payments for cryptocurrencies, specifically ERC-20 assets.
This contract consists of data types, events, and other types used by the Game contract and for testing.
With each play session, a player is given a specified time (e.g., three minutes) to move around the map collecting items that match their color. Collecting non-matching items decreases their size and remaining time, while matching items reward extra time and possibly one of the following:
- NFT
- Token
- Sablier Stream
Prizes are selected randomly based on the total number of items collected. The getWinnings
function requests random indexes from a globally defined prize pool set by the admin. Players must pass a signature signed by the game client when calling the getWinnings
function or submitting their scores to ensure fairness.
Players can be blacklisted or whitelisted by the admin based on defined criteria.
- Play on Chain A or Chain B
- Leaderboard
- Free Play
Building this project has been an enlightening experience. Some of the key takeaways include:
- Understanding the complexities of cross-chain communication.
- Learning how to implement Chainlink VRF for randomness in smart contracts.
- Realizing the importance of robust access control and security measures.
See Packages folder for individual project instructions
If you have any feedback, please create an issue and tag me.
While I currently don't have enough time to work on this project, here are some future plans if time allows:
- Fully test cross-chain play.
- Record each user play session and add it to the leaderboard for others to watch.
- Build a cross-chain NFT marketplace for users to trade their rewards.