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:
npx add-skill https://github.com/magicblock-labs/magicblock-dev-skill
Using Cursor, Codex, Windsurf, Cline, or another agent? See the AI Dev Skill page for all install targets.

Quick Access

Check out example:

GitHub

Private Counter Anchor Implementation

Live Example App

Try the Private Counter
MagicBlock’s Private Ephemeral Rollup enforces compliance based on node-level IP geofencing, OFAC-sanction list and restricted jurisdictions at ingress, before any transaction is accepted or executed. Find out more

Step-By-Step Guide

Build your program, delegate state to the TEE validator, and create an EphemeralPermission account directly on the ER via MagicBlock’s Permission Program ACLseoPoyC3cBqoUtkbjZ4aDrkurZW86v19pXz2XQnp1 and Delegation Program DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh:
1

Write your program

Write your Solana program as you normally.
2

Delegate and create permission

delegate delegates the counter to the TEE validator on the base layer. init_permission then runs on the ER — the delegated PDA signs as PDA and pays its own ephemeral permission rent (pre-funded at initialize time). set_privacy flips the public/private flag on demand. No base-layer permission account to create, delegate, or commit-and-undelegate. See access control details.

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 Solana program using Anchor CLI.
4

Implement authorization in your client

Sign user message to retrieve authorization token from TEE endpoint.
5

Execute transactions and test privacy

Request for authorization token and send confidential transactions.

Private Counter Example

The following software packages may be required, other versions may also be compatible:
SoftwareVersionInstallation Guide
Solana3.1.9Install Solana
Rust1.89.0Install Rust
Anchor1.0.2Install Anchor
Node24.10.0Install Node
The EphemeralPermission flow shown below requires ephemeral-rollups-sdk v0.14+ (introduces CreateEphemeralPermissionCpi / UpdateEphemeralPermissionCpi / CloseEphemeralPermissionCpi). For older SDK and Anchor versions, see legacy examples.

Code Snippets

A simple counter program with initialize and increment instructions, identical in shape to the public counter — privacy is added in the next steps:
#[ephemeral]
#[program]
pub mod private_counter {
    use super::*;

    /// Initialize the counter.
    pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
        let counter = &mut ctx.accounts.counter;
        counter.count = 0;
        Ok(())
    }

    /// Increment the counter.
    pub fn increment(ctx: Context<Increment>) -> Result<()> {
        let counter = &mut ctx.accounts.counter;
        counter.count += 1;
        Ok(())
    }

    /// ... Other instructions for delegation, permission, and privacy
}

pub const COUNTER_SEED: &[u8] = b"counter";

/// Context for initializing counter
#[derive(Accounts)]
pub struct Initialize<'info> {
    #[account(init_if_needed, payer = user, space = 8 + 8, seeds = [COUNTER_SEED], bump)]
    pub counter: Account<'info, Counter>,
    #[account(mut)]
    pub user: Signer<'info>,
    pub system_program: Program<'info, System>,
}

/// Context for incrementing counter
#[derive(Accounts)]
pub struct Increment<'info> {
    #[account(mut, seeds = [COUNTER_SEED], bump)]
    pub counter: Account<'info, Counter>,
}

/// Counter struct
#[account]
pub struct Counter {
    pub count: u64,
}

/// Other context and accounts for delegation and privacy ...
⬆️ Back to Top

Access Control

Fine-grained Access Control

On-chain Privacy

Privacy Mechanisms and Concepts

Authorization

Authorization Framework

Compliance Framework

Compliance Standards and Guidelines

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.