Skip to main content

Crank Counter

The Crank Counter example demonstrates how to use MagicBlock’s scheduled crank system to automatically execute instructions at specified intervals within Ephemeral Rollups. This advanced pattern enables autonomous program execution without manual intervention.

What Are Cranks?

Cranks are scheduled tasks that automatically execute specified instructions at regular intervals within an Ephemeral Rollup. This is particularly useful for:
  • Automated game state updates
  • Periodic reward distributions
  • Scheduled maintenance operations
  • Time-based game mechanics
Cranks execute entirely within the Ephemeral Rollup environment, providing low-latency automated execution without base layer transaction costs.

How It Works

Crank Parameters

Make sure your delegated account has sufficient commitment interval set to allow the crank to execute multiple times before automatic commits.

Program Setup

Your program must be annotated with the #[ephemeral] macro:
programs/crank-counter/src/lib.rs

Local Development

Use Cases

Cranks are particularly powerful for:
  • Gaming: Auto-advance turn-based games, periodic resource regeneration
  • DeFi: Scheduled interest calculations, automated liquidations
  • NFTs: Time-based trait updates, dynamic metadata changes
  • Social: Periodic content refresh, scheduled notifications

Next Steps