The Player Structure

How the players are stored in our game dApp smart-contract

Goals:

  • Being able to link a mirror wallet to a real player EOA

  • Being able to track its token allowance without holding any tokens on the mirror wallet

    /// @notice Player storage structure
    struct Player {
            /// @notice mirror address used to sign txns
        address internalAddress;
            /// @notice amount of GLMB loaded inside the game contract
        uint glmbAvailable;
            /// @notice amount of shakes available
        uint16 shakesAvailable;
            /// @notice counter for games played by this player
        uint gamesPlayed;
    }

Once we have this structure defined, we simply need to map it to the real EOA of the player.

    /// @notice Real Player Wallet -> Player Data
    mapping(address => Player) public players;

Now we can simply access the mapping from our back or front-end using ethers:

gameV2Contract.players(walletAddress)

Every property such as internalAddress, glmbAvailable or gamesPlayed will now be accessible!

Last updated