Skip to content

magicblock-labs/magicblock-engine-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

291 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

⚑ MagicBlock Engine - Integration Examples

Scaling solution for performant, composable games and applications.

✨Overview

This repository contains examples of how to use the different features available in an Ephemeral Rollup (ER). Read more about Ephemeral Rollups here.

To view integrated demos for specific usecases, please look at MagicBlock Starter Kits.

πŸ‘· Examples

🧱 Basic Examples

Core feature demos like delegation, randomness and privacy - the place to start.

βž• Anchor Counter

Anchor

Counter program in Anchor.

πŸ¦€ Rust Counter

Native Rust

Counter program in native Rust.

πŸͺ΅ Pinocchio Counter

Pinocchio

Counter program built with Pinocchio.

πŸ”’ Anchor Private Counter

Anchor Privacy

Anchor counter with permissions.

πŸͺ΅ Pinocchio Private Counter

Pinocchio Privacy

Pinocchio counter with magic permission accounts.

πŸ’° SPL Tokens

Anchor Tokens

SPL token delegation example with transfers on the ER.

πŸͺ™ Dummy Token Transfer

Anchor Tokens

Dummy SPL token onboarding.

🎲 Roll Dice

Anchor VRF

Dice roll using a verifiable random function (VRF) on the ER.

🎲 Pinocchio Roll Dice

Pinocchio VRF

Pinocchio VRF dice variant.

🧩 Feature Examples

Focused demos of individual capabilities β€” on-curve delegation, actions, ephemeral accounts, cranks, sessions.

πŸ“ˆ On-Curve Delegation

Anchor On-curve

Delegate on-curve accounts to the ER and manage their lifecycle.

✨ Magic Actions

Anchor Actions

Execute base-chain actions from inside an Ephemeral Rollup.

✨ Delegation Actions

Anchor Delegation

Attach actions that the ER runs automatically right after delegation.

πŸ’¬ Ephemeral Account Chats

Anchor Magic Accounts

Anchor chat program using "magic accounts" (ER-only).

⏱️ Crank Counter

Anchor Crank

Counter driven by MagicBlock's scheduled crank system.

πŸ”‘ Session Keys

Anchor Session Keys

Counter using gpl-session keys for delegated-signer auth on both base chain and ER.

🎨 Templates

End-to-end app templates you can fork and build on.

πŸ›‘οΈ Private Payments

Next.js Privacy

Next.js demo for MagicBlock private payments.

πŸ† Rewards (Delegated VRF)

Anchor VRF

Rewards distribution program using delegated VRF.

✊ Rock Paper Scissor

Anchor Privacy

Two-player RPS with hidden moves on the ER until reveal.

Testing

To run local tests for any example project, use the following steps:

  1. Install Dependencies (Local nodes + example directory):

    npm install -g @magicblock-labs/ephemeral-validator@latest
    cd <example-directory>
    yarn install
  2. Setup local nodes:

    yarn setup
  3. Run Tests Locally:

    yarn test:local

Example: To test the pinocchio-roll-dice example:

cd pinocchio-roll-dice
yarn build
yarn test:local

Local nodes

Setting up local nodes:

  • A Solana Test Validator preloaded with all the needed programs to work with ER.
  • A local Ephemeral Rollup.
  • The Query Filtering Service that replicates the privacy logic happening on TEE nodes, without hardware attestation.
graph LR
  User((User))
  SN["Solana Node:8899"]
  ER["Ephemeral Rollup:7799"]
  QFS["Query Filtering Service:6699"]

  SN <--> ER
  ER <--> QFS
  QFS <--> User
Loading

Set the endpoint to the QFS if you want to test privacy features, or to the ER directly otherwise.

Backward Compatibility

Older pre-Anchor 1.0 versions of the migrated programs are kept in 00-LEGACY_EXAMPLES. The 00- prefix keeps these compatibility references listed before the active examples in alphabetical folder views. These examples are for users who still need the previous Anchor 0.32.1 implementations while upgrading to the current Anchor 1.0 programs.