Getting Started
Magicblock
For a smooth gaming experience, our program integrates with Magicblock's Ephemeral Rollup. When the second player joins the game, we call and execute the joinGameIx instruction. After that, the game status changes to InProgress, and the GameAccount is delegated to the Ephemeral Rollup environment. To read data from the GameAccount, you need to switch your RPC to the Ephemeral Rollup RPC.
// Check game status and use appropriate RPC
const [gameAccountPDA] = await getGameAccountPDA(
address("YourIntegratorId"),
BigInt(1)
);
// First try with standard RPC
const maybeGameAccount = await fetchGameAccount(rpc, gameAccountPDA);
// If game is in progress, use Ephemeral Rollup RPC
if (
maybeGameAccount.exists &&
maybeGameAccount.data.gameStatus === GameStatus.InProgress
) {
// Use Ephemeral Rollup RPC
const gameAccount = await fetchGameAccount(erRpc, gameAccountPDA);
// Process game data...
} else {
// Use standard RPC data
// Process game data...
}- When the game finishes (for example, when one player achieves checkmate or a draw offer is accepted), the game status changes to Finished. The
GameAccountwill then be committed and undelegated back to Solana. To readGameAccountdata at this point, you can use the standard RPC. - Integrators should always check the game status to determine whether the
GameAccountis in the Ephemeral Rollup environment or not, in order to choose the correct RPC endpoint for reading data.