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
Core Components
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.
