This README is an auto generated progress update that explains how to build a simpler game server on-chain using Solana's Ephemeral Rollups.
# Build the program
anchor build
After building your program, you need to generate a program ID:
# Generate a new keypair for your program
solana-keygen new -o target/deploy/my_project-keypair.json
# Get the program ID
solana address -k target/deploy/my_project-keypair.json
- Copy the generated program ID
- Update
Anchor.toml
with your program ID:[programs.localnet] my_project = "YOUR_PROGRAM_ID"
- Update
declare_id!()
in your program'slib.rs
file:declare_id!("YOUR_PROGRAM_ID");
# Rebuild the program with the new ID
anchor build
# Set Solana to devnet
solana config set --url devnet
# Airdrop some SOL to your wallet for transaction fees
solana airdrop 2
# Deploy to devnet
anchor deploy
- Program ID Mismatch: Ensure the program ID in
Anchor.toml
andlib.rs
match exactly - Insufficient SOL: Make sure your wallet has enough SOL for deployment
- Build Errors: Run
anchor clean
before rebuilding if you encounter persistent errors
Ephemeral Rollups in Solana provide a way to offload computation from the base layer while maintaining security. They allow for:
- Faster transaction processing
- Lower costs
- Better user experience for interactive applications like games
- Maintaining security guarantees from the base layer
Delegation is the key mechanism that transfers control of an account from Solana's base layer to the Ephemeral Rollup.
When an account is delegated:
- The account's data is copied to the rollup
- The account becomes "locked" on the base layer (can't be modified directly)
- All operations on that account happen in the rollup until it's undelegated
- The account's ownership on the base layer changes to the Delegation Program
- Delegations work at the account level, not at individual fields
- Only data accounts get delegated, not program accounts (executable code)
- After delegation, there are effectively two copies of the account:
- The original (now locked) copy on the base layer
- The working copy in the rollup that can be modified
Use the #[delegate]
attribute macro to enable account delegation:
#[delegate]
#[derive(Accounts)]
pub struct DelegateInput<'info> {
pub payer: Signer<'info>,
/// CHECK: The account to delegate
#[account(mut, del)]
pub pda: AccountInfo<'info>,
}
Key points:
- The
#[delegate]
attribute generates code for account delegation - The account being delegated must use
AccountInfo<'info>
(not a deserialized account type) - Add
#[account(mut, del)]
to mark which account is being delegated
Add the #[ephemeral]
attribute to your program module to enable rollup functionality:
#[ephemeral]
#[program]
pub mod my_game {
// Program functions here
}
When delegating accounts, you must use AccountInfo<'info>
rather than deserialized Anchor account types:
❌ Incorrect:
#[account(mut, del)]
pub game_state: Account<'info, GameState>,
✅ Correct:
#[account(mut, del)]
pub game_state: AccountInfo<'info>,
Users interact with the program normally. The Anchor framework and Ephemeral Rollups SDK handle the routing:
- If an account is delegated, operations go to the rollup
- If not, they go to the base layer
When designing your game:
- Consider which accounts need delegation (typically game state accounts)
- Separate independent state into different accounts if they need independent control
- Structure your game state appropriately for the rollup environment
- Design clear flows for delegation and undelegation of game accounts
Ephemeral Rollups share similarities with Ethereum L2 solutions but with key differences:
Similarities:
- Both create environments for faster/cheaper transaction execution
- Both start with a copy of state from the original chain
Differences:
- Ephemeral Rollups operate at the account level, not the entire state
- The delegation mechanism is more granular in Solana
- The architecture leverages Solana's account model rather than Ethereum's global state model
- Start with a simple implementation (e.g., position data only)
- Test thoroughly on the base layer before adding rollup functionality
- Add delegation for your game state accounts
- Implement game logic that works with delegated accounts