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
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
- Explore Magic Actions for executing base chain handlers on commit
- Learn about Session Keys for gasless transactions
- Check the full source code