Overview
This guide demonstrates how to implement cranks using MagicBlock’s Ephemeral Rollups (ER) with the Anchor framework. The implementation follows this flow:- Initialize counter on Solana base layer
- Delegate counter account to Ephemeral Rollup for faster execution
- Schedule a crank task that automatically increments the counter
- Execute the crank automatically at specified intervals
- Undelegate the account back to Solana base layer when done
Execution Flow
This guide describes the scheduler in validator 1.1.1, which the mainnet ERs and devnet-eu/devnet-as run. devnet-us runs validator 2.0.0, where cranks run through Hydra and
ScheduleTask rejects any signer account in the scheduled instruction.Core Components
Dependencies
Besidesanchor-lang, the snippets below use these crates and imports:
Scheduled Function
Let’s take for example that you wanted to schedule the following simple increment instruction for a counter.Schedule Increment Function
The core crank scheduling logic:- Creates an instruction to increment the counter
- Serializes it into a
ScheduleTaskinstruction for MagicBlock - Uses CPI (Cross-Program Invocation) to call the MagicBlock program
- The MagicBlock program handles the scheduling and execution
Schedule Arguments
ScheduleIncrement Context
AccountInfo instead of Account<Counter> to avoid Anchor re-serializing stale data after CPI calls.
