Skip to main content

Overview

The TypeScript SDK provides functions and utilities to interact with MagicBlock Ephemeral Rollups from client applications. It includes delegation helpers, PDA derivation, connection management, and Bolt ECS integration.

Installation

For Bolt ECS applications:

Core Exports

Constants

PublicKey
The program ID of the delegation program used to delegate accounts to Ephemeral Rollups
PublicKey
The program ID of the magic program used for committing accounts from ER back to Solana
PublicKey
The magic context account required for commit operations

Connection Management

Setting up Connections

Establish separate connections for Solana base layer and Ephemeral Rollups:

PDA Helpers

delegationRecordPdaFromDelegatedAccount

Derives the delegation record PDA for a delegated account.
PublicKey
required
The account being delegated
PublicKey
The derived delegation record PDA

delegationMetadataPdaFromDelegatedAccount

Derives the delegation metadata PDA for a delegated account.
PublicKey
required
The account being delegated
PublicKey
The derived delegation metadata PDA

delegateBufferPdaFromDelegatedAccountAndOwnerProgram

Derives the delegation buffer PDA for a delegated account and its owner program.
PublicKey
required
The account being delegated
PublicKey
required
The program that owns the delegated account
PublicKey
The derived delegation buffer PDA

Delegation Instructions

While programs typically handle delegation via CPI, you can construct delegation instructions manually for testing or custom flows.

Manual Delegation Example

Commitment Operations

GetCommitmentSignature

Waits for and returns the base layer commitment signature after committing state from ER.
string
required
The transaction hash of the commit transaction sent on the Ephemeral Rollup
Connection
required
The Ephemeral Rollup connection instance
string
The transaction signature on the base layer Solana chain

Commit Transaction Example

Bolt SDK (ECS)

For Bolt Entity Component System applications, use the Bolt SDK for specialized ECS operations.

Installation

Imports

ApplySystem

Executes a system on entities with specified components in the Bolt ECS framework.
PublicKey
required
The wallet with authority to execute the system
PublicKey
required
The world PDA in which the system operates
Array<{ entity: PublicKey, components: Array<{ componentId: PublicKey }> }>
required
Array of entities and their components that the system will operate on
PublicKey
required
The program ID of the system to execute
Transaction
The constructed transaction ready to be signed and sent

FindComponentPda

Finds the PDA for a component attached to an entity.
PublicKey
required
The program ID of the component
PublicKey
required
The entity PDA
PublicKey
The derived component PDA

createDelegateInstruction

Creates an instruction to delegate a Bolt component to an Ephemeral Rollup.
PublicKey
required
The entity that owns the component
PublicKey
required
The component account to delegate
PublicKey
required
The component’s program ID
PublicKey
required
The account paying for the delegation
TransactionInstruction
The delegation instruction

createUndelegateInstruction

Creates an instruction to undelegate a Bolt component from an Ephemeral Rollup.
PublicKey
required
The account paying for the undelegation
PublicKey
required
The component account to undelegate
PublicKey
required
The component’s program ID
TransactionInstruction
The undelegation instruction

Complete Example

Here’s a complete workflow demonstrating delegation, execution on ER, and undelegation:

Network Endpoints

Devnet

  • Base Layer: https://api.devnet.solana.com (wss: wss://api.devnet.solana.com)
  • Ephemeral Rollups: https://devnet-as.magicblock.app/ (wss: wss://devnet-as.magicblock.app/)

Localnet

When running against localnet, you may need to include the validator identity as a remaining account: