Skip to main content

Setup

Use Magic Router to route transactions to ER and base layer.
import { Connection } from "@solana/web3.js";
import { sendMagicTransaction } from "@magicblock-labs/ephemeral-rollups-sdk";

const routerConnection = new Connection(
  "https://devnet-router.magicblock.app",
  { wsEndpoint: "wss://devnet-router.magicblock.app" }
);

Flow

  1. Delegate an account to ER
const delegateTx = await program.methods
  .delegate()
  .accounts({ payer: wallet.publicKey, pda: yourAccountPda })
  .transaction();
await sendMagicTransaction(routerConnection, delegateTx, [wallet.payer]);
  1. Execute fast transactions on ER
const executeTx = await program.methods
  .yourEphemeralInstruction()
  .accounts({ /* your accounts */ })
  .transaction();
await sendMagicTransaction(routerConnection, executeTx, [wallet.payer]);
  1. Commit with automatic handler execution
const commitTx = await program.methods
  .commitWithAction()
  .accounts({ payer: wallet.publicKey /* your accounts */ })
  .transaction();
await sendMagicTransaction(routerConnection, commitTx, [wallet.payer]);

Examples

I