Skip to main content

Overview

This guide demonstrates how to implement cranks using MagicBlock’s Ephemeral Rollups (ER) with the Anchor framework. The implementation follows this flow:
  1. Initialize counter on Solana base layer
  2. Delegate counter account to Ephemeral Rollup for faster execution
  3. Schedule a crank task that automatically increments the counter
  4. Execute the crank automatically at specified intervals
  5. 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:
Key Points:
  • Creates an instruction to increment the counter
  • Serializes it into a ScheduleTask instruction for MagicBlock
  • Uses CPI (Cross-Program Invocation) to call the MagicBlock program
  • The MagicBlock program handles the scheduling and execution

Schedule Arguments

ScheduleIncrement Context

Important: Uses AccountInfo instead of Account<Counter> to avoid Anchor re-serializing stale data after CPI calls.