### Basic Usage of ConnectionMagicRouter Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/ts/web3js/README.md Import the ConnectionMagicRouter to begin using the SDK. Refer to the quickstart guide for comprehensive examples and documentation. ```typescript import { ConnectionMagicRouter } from "@magicblock-labs/ephemeral-rollups-sdk"; // See full examples and docs in the Quickstart link above. ``` -------------------------------- ### Basic Usage: Wallet Sponsor with `#[ephemeral_accounts]` Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/rust/ephemeral-accounts-attribute/README.md Demonstrates using the `#[ephemeral_accounts]` macro with a wallet as the sponsor for ephemeral accounts. Includes examples for creating, initializing if needed, resizing, and closing ephemeral accounts. ```rust use anchor_lang::prelude::*; use ephemeral_rollups_sdk::anchor::ephemeral_accounts; #[ephemeral_accounts] #[derive(Accounts)] pub struct CreateGame<'info> { #[account(mut, sponsor)] // <-- sponsor pays rent pub payer: Signer<'info>, /// CHECK: Ephemeral account #[account( mut, eph, // <-- ephemeral marker seeds = [b"game", payer.key().as_ref()], bump, )] pub game_state: AccountInfo<'info>, } // Create ephemeral account pub fn create_game(ctx: Context) -> Result<()> { ctx.accounts.create_ephemeral_game_state(1000)?; Ok(()) } // Create only if doesn't exist (like Anchor's init_if_needed) pub fn create_game_if_needed(ctx: Context) -> Result<()> { ctx.accounts.init_if_needed_ephemeral_game_state(1000)?; Ok(()) } // Resize existing account pub fn resize_game(ctx: Context) -> Result<()> { ctx.accounts.resize_ephemeral_game_state(2000)?; Ok(()) } // Close and refund rent pub fn close_game(ctx: Context) -> Result<()> { ctx.accounts.close_ephemeral_game_state()?; Ok(()) } ``` -------------------------------- ### Install Ephemeral Rollups SDK with yarn Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/ts/web3js/README.md Use this command to install the SDK using yarn. ```bash yarn add @magicblock-labs/ephemeral-rollups-sdk ``` -------------------------------- ### Install Ephemeral Rollups SDK with npm Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/ts/web3js/README.md Use this command to install the SDK using npm. ```bash npm install @magicblock-labs/ephemeral-rollups-sdk ``` -------------------------------- ### Install @magicblock-labs/ephemeral-rollups-kit with yarn Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/ts/kit/README.md Use this command to install the package using yarn. ```bash yarn add @magicblock-labs/ephemeral-rollups-kit ``` -------------------------------- ### Basic Usage of Ephemeral Rollups Kit Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/ts/kit/README.md Import the Connection class from the library to begin preparing and routing transactions. Refer to the Quickstart guide for comprehensive examples. ```typescript import { Connection } from "@magicblock-labs/ephemeral-rollups-kit"; // See full examples and docs in the Quickstart link above. ``` -------------------------------- ### Install @magicblock-labs/ephemeral-rollups-kit with npm Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/ts/kit/README.md Use this command to install the package using npm. ```bash npm install @magicblock-labs/ephemeral-rollups-kit ``` -------------------------------- ### Run All Integration Tests Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/rust/tests/README.md Execute all integration tests in the workspace. Ensure you are in the project root directory. ```bash cargo test ``` -------------------------------- ### Run Integration Tests with Output Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/rust/tests/README.md Run all integration tests and display their output. This is useful for debugging. ```bash cargo test -- --nocapture ``` -------------------------------- ### On-Chain Ephemeral Account with Keypair Sponsor Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/rust/ephemeral-accounts-attribute/README.md Illustrates setting up an ephemeral account that is backed by a keypair. This ephemeral account must sign the transaction, and no seeds are needed for its definition. ```rust #[ephemeral_accounts] #[derive(Accounts)] pub struct CreateWithKeypair<'info> { #[account(mut, sponsor)] pub payer: Signer<'info>, /// CHECK: Oncurve ephemeral - must sign the transaction #[account(mut, eph)] pub temp_account: Signer<'info> // No seeds needed } ``` -------------------------------- ### Delegate Account with #[delegate] Macro Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/rust/delegate/README.md Use the `#[delegate]` macro on your Accounts struct to automatically generate delegation fields and methods. Ensure the account to be delegated has the `del` marker. ```rust use anchor_lang::prelude::*; use ephemeral_rollups_sdk::anchor::delegate; #[delegate] #[derive(Accounts)] pub struct DelegatePlayer<'info> { #[account(mut)] pub payer: Signer<'info>, #[account(mut, del)] // <-- delegation marker pub player: Account<'info, PlayerState>, } pub fn delegate_player(ctx: Context) -> Result<()> { let seeds: &[&[u8]] = &[b"player", ctx.accounts.payer.key.as_ref()]; ctx.accounts.delegate_player( &ctx.accounts.payer, seeds, DelegateConfig::default(), )?; Ok(()) } ``` -------------------------------- ### PDA Sponsor with `#[ephemeral_accounts]` Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/rust/ephemeral-accounts-attribute/README.md Shows how to use a Program Derived Address (PDA) as the sponsor for ephemeral accounts. The `sponsor` attribute is applied to the PDA account. ```rust #[ephemeral_accounts] #[derive(Accounts)] pub struct CreateGameWithTreasury<'info> { /// CHECK: PDA treasury as sponsor #[account( mut, sponsor, seeds = [b"treasury"], bump, )] pub treasury: AccountInfo<'info>, /// CHECK: Ephemeral account #[account( mut, eph, seeds = [b"game", treasury.key().as_ref()], bump, )] pub game_state: AccountInfo<'info>, } ``` -------------------------------- ### Multiple Ephemeral Accounts with `#[ephemeral_accounts]` Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/rust/ephemeral-accounts-attribute/README.md Demonstrates how to manage multiple ephemeral accounts within a single `#[derive(Accounts)]` struct. The macro generates corresponding methods for each ephemeral field. ```rust #[ephemeral_accounts] #[derive(Accounts)] pub struct MultiEphemeral<'info> { #[account(mut, sponsor)] pub payer: Signer<'info>, /// CHECK: First ephemeral account #[account(mut, eph, seeds = [b"player", payer.key().as_ref()], bump)] pub player_state: AccountInfo<'info>, /// CHECK: Second ephemeral account #[account(mut, eph, seeds = [b"game", payer.key().as_ref()], bump)] pub game_state: AccountInfo<'info>, } pub fn create_both(ctx: Context) -> Result<()> { ctx.accounts.init_if_needed_ephemeral_player_state(100)?; ctx.accounts.init_if_needed_ephemeral_game_state(200)?; Ok(()) } ``` -------------------------------- ### Run Specific Integration Test Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/rust/tests/README.md Execute a single integration test by its name. Replace `` with the actual name of the test you want to run. ```bash cargo test --test ``` -------------------------------- ### Calculate Ephemeral Account Rent Cost Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/rust/ephemeral-accounts-attribute/README.md Provides a Rust code snippet demonstrating how to calculate the rent cost for an ephemeral account of a given size using the `rent` function from the SDK. ```rust use ephemeral_rollups_sdk::ephemeral_accounts::rent; let cost = rent(1000); // Cost for 1KB account // cost = (1000 + 60) * 32 = 33,920 lamports ``` -------------------------------- ### Run Specific Test File Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/rust/tests/TEST_SUMMARY.md Execute tests contained within a particular test file. Replace `integration_test` with the desired test file name. ```bash cargo test --test integration_test ``` ```bash cargo test --test access_control_test ``` ```bash cargo test --test pinocchio_test ``` ```bash cargo test --test resolver_test ``` ```bash cargo test --test sdk_test ``` ```bash cargo test --test macros_test ``` -------------------------------- ### Run Specific Test Function Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/rust/tests/TEST_SUMMARY.md Execute a single test function by its name. This is useful for quickly testing a specific piece of functionality. ```bash cargo test test_group_constants ``` -------------------------------- ### Add Ephemeral Rollups SDK Dependency Source: https://github.com/magicblock-labs/ephemeral-rollups-sdk/blob/main/rust/delegate/README.md Add the ephemeral-rollups-sdk to your Cargo.toml file with the 'anchor' feature enabled. ```toml [dependencies] ephemeral-rollups-sdk = { version = "0.8", features = ["anchor"] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.