Brianspha / chainlink_game

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No Name Game

This is a Proof of Concept (POC) cross-chain game that can be deployed on any EVM chain.

Badges

MIT License

Table of Contents

  1. Overview
  2. Smart Contracts
    1. Access Control
    2. Game Contract
    3. NFT Contract
    4. Token Contract
    5. Game Attestation Contract
    6. VRF Contracts
    7. Stream Creator Contract
    8. Game Utils
  3. Rewards
  4. Screenshots
  5. Tech Stack
  6. Features
  7. Lessons Learned
  8. Run Locally
  9. Environment Variables
  10. Acknowledgements
  11. Feedback
  12. Future Plans
  13. License

Overview

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.

Overview

Smart Contracts

Access Control

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

Game Contract

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:

This works vice versa aswell

NFT Contract

The NFT contract is used to reward users who have collected in-game items.

Token Contract

The Token contract is used to reward users who have collected in-game items and to define the PlayToken used to play the game.

Game Attestation Contract

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.

VRF Contracts

These contracts facilitate the requesting of random numbers. They are modified to work locally for better testing without needing to fork existing implementations.

Stream Creator Contract

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.

Game Utils

This contract consists of data types, events, and other types used by the Game contract and for testing.

Rewards

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.

Blacklisting or Whitelisting

Players can be blacklisted or whitelisted by the admin based on defined criteria.

Screenshots

  1. App Screenshot 1
  2. App Screenshot 2
  3. App Screenshot 3
  4. App Screenshot 4
  5. App Screenshot 5
  6. App Screenshot 6
  7. App Screenshot 7
  8. App Screenshot 8

Tech Stack

JavaScript Vue.js Vuetify
Solidity
Foundry Hardhat
Vite Excalidraw

Features

  • Play on Chain A or Chain B
  • Leaderboard
  • Free Play

Lessons Learned

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.

Run Locally

See Packages folder for individual project instructions

Acknowledgements

Feedback

If you have any feedback, please create an issue and tag me.

Future Plans

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.

About


Languages

Language:Solidity 69.4%Language:Vue 16.6%Language:JavaScript 13.7%Language:HTML 0.2%