Skip to content

magicblock-labs/magicblock-engine-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

309 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.

βž• Counter / Anchor

Anchor

Counter program in Anchor.

πŸ¦€ Counter / Native Rust

Native Rust

Counter program in native Rust.

πŸͺ΅ Counter / Pinocchio

Pinocchio

Counter program built with Pinocchio.

πŸ”’ Private Counter / Anchor

Anchor Privacy

Anchor counter with permissions.

πŸͺ΅ Private Counter / Pinocchio

Pinocchio Privacy

Pinocchio counter with magic permission accounts.

πŸ’° SPL Tokens / Anchor

Anchor Tokens

SPL token delegation, ER transfers, and withdrawal back to base layer.

🎲 Roll Dice / Anchor

Anchor VRF

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

🎲 Roll Dice / Pinocchio

Pinocchio VRF

Pinocchio VRF dice variant.

πŸ“Š Oracle Priced Purchase / Anchor

Anchor Oracle

USD-priced token purchase using real-time oracle prices.

🧩 Feature Examples

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

πŸ“ˆ On-Curve Delegation / Client

Anchor On-curve

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

✨ Magic Actions / Anchor

Anchor Actions

Execute base-chain actions from inside an Ephemeral Rollup.

✨ Delegation Actions / Anchor

Anchor Delegation

Attach actions that the ER runs automatically right after delegation.

πŸ’¬ Ephemeral Account Chats / Anchor

Anchor Magic Accounts

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

⏱️ Crank Counter / Anchor

Anchor Crank

Counter driven by MagicBlock's scheduled crank system.

πŸ”‘ Session Keys / Anchor

Anchor Session Keys

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

πŸ“ˆ Binary Prediction / Anchor

Anchor Price Oracle Session Keys

Up/down SPL-token prediction flow using session keys and an ER price oracle.

🎨 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

Anchor VRF

Rewards distribution program using delegated VRF.

✊ Rock Paper Scissor / Anchor

Anchor Privacy

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

πŸͺ„ Magic Gachapon

Next.js VRF Metaplex Core

MagicBlock VRF gachapon demo that mints a Metaplex Core NFT reward.

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 roll-dice/pinocchio
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.

About

Ephemeral Rollups - Integration Examples

Resources

License

Stars

50 stars

Watchers

1 watching

Forks

Contributors