Skip to main content

Building with an AI coding agent? Install the MagicBlock Dev Skill to give your agent MagicBlock-specific patterns — delegation flows, Magic Actions, cranks, VRF, and more.Quick install for Claude Code:
Using Cursor, Codex, Windsurf, Cline, or another agent? See the AI Dev Skill page for all install targets.

Quick Access

Check out basic counter example:

GitHub

Anchor Implementation

GitHub

React Implementation


Step-By-Step Guide

Build your program and upgrade it with delegation hooks with MagicBlock’s Delegation Program DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh:
1

Write your program

Write your Solana program as you normally would.
2

Add delegation and undelegation hooks in your program

Add CPI hooks to delegate, commit and undelegate state accounts through Ephemeral Rollup sessions.

These public validators are supported for development. Make sure to add the specific ER validator in your delegation instruction:

Mainnet
  • Asia (as.magicblock.app): MAS1Dt9qreoRMQ14YQuhg8UTZMMzDdKhmkZMECCzk57
  • EU (eu.magicblock.app): MEUGGrYPxKk17hCr7wpT6s8dtNokZj5U2L57vjYMS8e
  • US (us.magicblock.app): MUS3hc9TCw4cGC12vHNoYcCGzJG1txjgQLZWVoeNHNd
  • TEE (mainnet-tee.magicblock.app): MTEWGuqxUpYZGFJQcp8tLN7x5v9BSeoFHYWQQ3n3xzo
Devnet
  • Asia (devnet-as.magicblock.app): MAS1Dt9qreoRMQ14YQuhg8UTZMMzDdKhmkZMECCzk57
  • EU (devnet-eu.magicblock.app): MEUGGrYPxKk17hCr7wpT6s8dtNokZj5U2L57vjYMS8e
  • US (devnet-us.magicblock.app): MUS3hc9TCw4cGC12vHNoYcCGzJG1txjgQLZWVoeNHNd
  • TEE (devnet-tee.magicblock.app): MTEWGuqxUpYZGFJQcp8tLN7x5v9BSeoFHYWQQ3n3xzo
Localnet
  • Local ER (localhost:7799): mAGicPQYBMvcYveUZA5F5UNNwyHvfYh5xkLS2Fr1mev
3

Deploy your program on Solana.

Deploy your program directly on Solana using Anchor or Solana CLI.
4

Ready to execute transactions for delegation and real-time speed

Send transactions without modifications on-chain and off-chain that also comply with the SVM RPC specification.

Counter Example

Counter GIF The following software packages may be required, other versions may also be compatible:

Code Snippets

The program implements two main instructions:
  1. initialize: Sets the counter to 0
  2. increment: Increments the counter by 1
The program implements specific instructions for delegating and undelegating the counter:
  1. Delegate: Delegates counter from Base Layer to ER (called on Base Layer)
  2. CommitAndUndelegate: Schedules sync of counter from ER to Base Layer, and undelegates counter on ER (called on ER)
  3. Commit: Schedules sync of counter from ER to Base Layer (called on ER)
  4. Undelegate:
    • Schedules sync and undelegation of counter (called on ER)
    • Undelegation triggered through callback instruction injected through #[ephemeral] (called on Base Layer through validator CPI)
The undelegation callback discriminator [196, 28, 41, 206, 48, 37, 51, 167] and its instruction processor must be specified in your program. This instruction triggered by Delegation Program reverts account ownership on the Base Layer after calling undelegation on ER.With [#ephemeral] Anchor macro from MagicBlock’s Ephemeral Rollup SDK, the undelegation callback discriminator and processor are injected into your program.
Nothing special here, just a simple Anchor program that increments a counter. The only difference is that we’re adding the ephemeral macro for undelegation and delegate macro to inject some useful logic to interact with the delegation program.⬆️ Back to Top

Advanced Code Snippets

When resizing a delegated PDA:
  • PDA must have enough lamports to remain rent-exempt for the new account size.
  • If additional lamports are needed, the payer account must be delegated to provide the difference.
  • PDA must be owned by the program, and the transaction must include any signer(s) required for transferring lamports.
  • Use system_instruction::allocate
⬆️ Back to Top

Quick Access

Learn more about private ER, Rust Native implementation, and local development:

Private Ephemeral Rollups (PER)

Quickstart

Rust Native

Quickstart

Guide

Local Development

Solana Explorer

Get insights about your transactions and accounts on Solana:

Solana Explorer

Official Solana Explorer

Solscan

Explore Solana Blockchain

Solana RPC Providers

Send transactions and requests through existing RPC providers:

Solana

Free Public Nodes

Helius

Free Shared Nodes

Triton

Dedicated High-Performance Nodes

Solana Validator Dashboard

Find real-time updates on Solana’s validator infrastructure:

Solana Beach

Get Validator Insights

Validators App

Discover Validator Metrics

Server Status

Subscribe to Solana’s and MagicBlock’s server status:

Solana Status

Subscribe to Solana Server Updates

MagicBlock Status

Subscribe to MagicBlock Server Status

MagicBlock Products

Ephemeral Rollup (ER)

Execute real-time, zero-fee transactions securely on Solana.

Private Ephemeral Rollup (PER)

Protect sensitive data with compliance — built on top of Ephemeral Rollups.

Private Payment API

Add private onchain transfers to your app in seconds — compliant by default.

Solana VRF

Add provably fair onchain randomness to games, raffles, and real-time apps.

Pricing Oracle

Access low-latency onchain price feeds for trading and DeFi.