✨High-Level API: The AppHelper
Introduction
The AppHelper is your primary entry point for performing common, stateless actions on the RACE Protocol. It provides a simplified, high-level interface for tasks like creating games, fetching account data, and managing player profiles without needing to manage a persistent real-time connection.
Key characteristics of the AppHelper:
Stateless: Each method call is an independent, one-off operation.
Action-Oriented: Designed for actions like "create," "get," "list," and "join."
Blockchain-Agnostic: The same
AppHelpermethods are used regardless of the underlying blockchain (Solana, Sui, etc.), thanks to the Transport Layer abstraction.Ideal for Web Servers and Scripts: Perfect for backend services, administrative scripts, or web frontends that only need to perform specific transactions or queries without subscribing to real-time game events.
In contrast, the AppClient (covered in The App Client) is stateful and designed to maintain a persistent WebSocket connection to a specific game instance, making it ideal for building real-time game clients. For many applications, you will use both: the AppHelper to discover and create games, and the AppClient to play them.
Initialization
To use the AppHelper, you must first initialize it with a Transport. The transport is the bridge that connects the SDK to a specific blockchain network. The SDK provides several transports out of the box.
The AppHelper itself is stateless, so you only need to provide the transport during initialization. The user's wallet is passed into the specific methods that require a transaction to be signed.
Initializing with FacadeTransport (for local development)
The FacadeTransport is a mock transport that simulates a blockchain environment, making it perfect for local development, tutorials, and testing without needing a real wallet or connection to a live network.
Initializing with SolanaTransport
To connect to the Solana blockchain, use the SolanaTransport.
Initializing with SuiTransport
To connect to the Sui blockchain, use the SuiTransport.
Game Management
These methods cover the lifecycle of a game, from creation and discovery to its conclusion.
Creating a Game (createGame)
createGame)This method creates a new game account on the blockchain. It returns a ResponseStream (covered in Core Concepts) that allows you to track the transaction's lifecycle.
Parameters (CreateGameAccountParams):
CreateGameAccountParams):title: The public name of the game (max 16 characters).bundleAddr: The on-chain address of theGameBundlecontaining the game's logic.tokenAddr: The address of the SPL token or native currency used for deposits.maxPlayers: The maximum number of players that can join.entryType: An object defining the entry conditions.Example for a cash game:
{ kind: 'cash', minDeposit: 1000n, maxDeposit: 10000n }Example for a ticket game:
{ kind: 'ticket', amount: 100n }
registrationAddr: The address of a public registry where the game will be listed.recipientAddr: The address of the RecipientAccount that will collect fees and winnings.data: AUint8Arrayof initial data to configure the game state.
Fetching Games (getGame and listGames)
getGame and listGames)You can fetch the on-chain data for a single game or a list of games from a registration account.
Registering and Closing a Game
registerGame(wallet, gameAddr, regAddr): Adds an existing game to a registration list to make it discoverable.closeGame(wallet, regAddr, gameAddr): Closes a game account. This is typically done by the owner after a game has concluded to manage on-chain assets and reclaim rent.
Player Actions
These methods are used to manage player identity and game entry.
Creating a Player Profile (createProfile)
createProfile)A player profile is a player's on-chain identity, including a nickname and an optional PFP NFT. This is often required before joining a game.
Making a Deposit (deposit)
deposit)For games that allow it, players can add more funds after joining.
Interacting with Assets
The AppHelper also includes utilities for querying and managing on-chain assets related to the RACE ecosystem.
Listing Tokens and NFTs (listTokens, listNfts)
listTokens, listNfts)These methods query a wallet's holdings. You can optionally provide a Storage implementation to cache the results and improve performance.
Managing Game Bonuses and Rewards (attachBonus, claim)
attachBonus, claim)attachBonus(wallet, gameAddr, bonuses): Allows a game owner or sponsor to attach additional token prizes to a game. bonuses is an array of{ identifier, tokenAddr, amount }.previewClaim(wallet, recipientAddr): A read-only method to see what funds are available for a recipient to claim from a game's fee/prize pool.claim(wallet, recipientAddr): Executes the transaction to withdraw claimable funds to the recipient's wallet.
Last updated