Overview
The Rust SDK (ephemeral-rollups-sdk) provides on-chain program utilities for integrating with MagicBlock Ephemeral Rollups. It includes delegation functions, commit operations, Anchor macros, and CPI helpers.
Installation
Add to yourCargo.toml:
Features
feature
Enables Anchor framework integration with macros and helpers
feature
Disables automatic account reallocation during delegation (recommended for production)
Anchor Integration
Imports
Macros
#[ephemeral]
Marks a program module as ephemeral-enabled, allowing it to run on both Solana and Ephemeral Rollups.macro
Apply to
#[program] modules to enable Ephemeral Rollups compatibility#[delegate]
Adds delegation functionality to an Anchor account context struct.delegate_pda method on the context:
macro
Apply to Anchor
Accounts structs containing accounts to delegate. Mark delegated accounts with #[account(mut, del)]#[commit]
Adds commit functionality to an Anchor account context struct.magic_program and magic_context accounts:
macro
Apply to Anchor
Accounts structs to automatically include magic program and context accounts required for commitsCPI Functions (Native Programs)
delegate_account
Delegates an account to the Ephemeral Rollups delegation program via CPI.DelegateAccounts
required
Struct containing all required account infos for delegation
&[&[u8]]
required
The seeds used to derive the PDA being delegated
DelegateConfig
required
Configuration for the delegation operation
DelegateAccounts
Struct containing all accounts required for delegation.&AccountInfo
required
The account paying for delegation costs (rent, fees)
&AccountInfo
required
The PDA account being delegated to the Ephemeral Rollup
&AccountInfo
required
The program that owns the PDA being delegated
&AccountInfo
required
The delegation buffer PDA (stores delegated account data)
&AccountInfo
required
The delegation record PDA (tracks delegation state)
&AccountInfo
required
The delegation metadata PDA (additional delegation info)
&AccountInfo
required
The delegation program account
&AccountInfo
required
The Solana system program
DelegateConfig
Configuration struct for delegation operations.Option<Pubkey>
Optional specific validator to delegate to. If
None, uses the default ER validatorOption<u32>
Optional commit frequency in milliseconds. If
None, uses default frequencyundelegate_account
Undelegates an account from the Ephemeral Rollups delegation program via CPI.&AccountInfo
required
The PDA account to undelegate
&Pubkey
required
The program that owns the delegated PDA
&AccountInfo
required
The delegation buffer account
&AccountInfo
required
The account paying for undelegation
&AccountInfo
required
The Solana system program
Vec<Vec<u8>>
required
The seeds used to derive the PDA
Commit Functions
commit_accounts
Commits account state from Ephemeral Rollup back to Solana base layer.&AccountInfo
required
The account paying for the commit operation
Vec<&AccountInfo>
required
Vector of accounts to commit back to base layer
&AccountInfo
required
The magic context account (required for commits)
&AccountInfo
required
The magic program account (required for commits)
commit_and_undelegate_accounts
Commits account state and undelegates in a single operation.&AccountInfo
required
The account paying for the operation
Vec<&AccountInfo>
required
Vector of accounts to commit and undelegate
&AccountInfo
required
The magic context account
&AccountInfo
required
The magic program account
Complete Examples
Anchor Program with Delegation
Native Program with CPI
VRF Integration
For programs using verifiable random functions with Ephemeral Rollups:Version Compatibility
- SDK Version: 0.6.5
- Anchor: 0.32.1+ (when using anchor feature)
- Solana: 1.18+
Best Practices
- Always use
disable-reallocfeature in production to prevent unexpected account size changes - Serialize Anchor accounts before committing using
.exit()method - Include validator in remaining_accounts for localnet testing
- Use
#[ephemeral]macro on all program modules that need ER support - Call commit operations only from ER, not from base layer