Overview
Delegation instructions transfer account ownership to the MagicBlock delegation program, enabling accounts to be processed on Ephemeral Rollups (ER). This page documents delegation patterns across Anchor and native Rust programs.Anchor Delegation Pattern
Using the #[delegate] Macro
The#[delegate] macro automatically generates the required delegation accounts and helper methods.
anchor-counter/programs/anchor-counter/src/lib.rs
Delegate Instruction Implementation
The delegate instruction uses the generateddelegate_pda method:
anchor-counter/programs/anchor-counter/src/lib.rs
DelegateInput Accounts
Signer
required
The account paying for delegation buffer and record creation
AccountInfo
required
The PDA account to delegate. Must be marked with
#[account(mut, del)]Program
System program (auto-generated by #[delegate] macro)
Program
The program that owns the PDA (auto-generated by #[delegate] macro)
AccountInfo
Buffer account for storing delegated account data (auto-generated)
AccountInfo
Record tracking the delegation state (auto-generated)
AccountInfo
Metadata about the delegation (auto-generated)
Program
The MagicBlock delegation program (auto-generated)
DelegateConfig Parameters
pda_seeds
&[&[u8]]
required
The seeds used to derive the PDA. Required for the delegation program to verify PDA ownership.
validator
Option<Pubkey>
Optional validator public key to specify which Ephemeral Rollup validator should process this account.
- If
None, uses the default validator - Can be provided via
remaining_accountsin Anchor
commit_frequency_ms
Option<u32>
Optional commit frequency in milliseconds. Controls how often the ER automatically commits account state back to the base layer.
- If
None, uses default commit frequency - Specified in milliseconds
Native Rust Delegation Pattern
Delegate Account Function
For native Rust programs, use thedelegate_account function from the SDK:
rust-counter/src/processor.rs
Native Rust Required Accounts
Signer
required
The payer and signer for the delegation transaction
AccountInfo
required
The Solana system program
AccountInfo
required
The PDA account being delegated
AccountInfo
required
The program that owns the PDA being delegated
AccountInfo
required
Buffer account for storing the delegated account’s data
AccountInfo
required
Record account tracking the delegation state
AccountInfo
required
Metadata account for the delegation
AccountInfo
required
The MagicBlock delegation program
AccountInfo
Optional validator account for specifying the ER validator
Pinocchio Delegation Pattern
Using Pinocchio SDK
The Pinocchio framework provides its own delegation function:pinocchio-counter/src/processor.rs
The Pinocchio pattern requires an explicit
bump parameter for PDA derivation.Best Practices
- Always validate PDA seeds - Ensure the PDA can be properly derived before delegation
- Specify validator when needed - Use the validator parameter for targeting specific ER nodes
- Use remaining_accounts for flexibility - Pass optional validator through remaining accounts
- Set appropriate commit frequency - Balance between data freshness and transaction costs
Related Instructions
- Commit Instructions - Manual commit and undelegation
- Program Instructions - Other program-specific operations