Documentation Index
Fetch the complete documentation index at: https://mintlify.com/magicblock-labs/magicblock-engine-examples/llms.txt
Use this file to discover all available pages before exploring further.
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
The account paying for delegation buffer and record creation
The PDA account to delegate. Must be marked with
#[account(mut, del)]System program (auto-generated by #[delegate] macro)
The program that owns the PDA (auto-generated by #[delegate] macro)
Buffer account for storing delegated account data (auto-generated)
Record tracking the delegation state (auto-generated)
Metadata about the delegation (auto-generated)
The MagicBlock delegation program (auto-generated)
DelegateConfig Parameters
pda_seeds
The seeds used to derive the PDA. Required for the delegation program to verify PDA ownership.
validator
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
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
The payer and signer for the delegation transaction
The Solana system program
The PDA account being delegated
The program that owns the PDA being delegated
Buffer account for storing the delegated account’s data
Record account tracking the delegation state
Metadata account for the delegation
The MagicBlock delegation program
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