### Install and Start Application Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/session-keys/app/README.md Install project dependencies and start the application using either Npm or Yarn. ```bash npm install npm run start ``` ```bash yarn install yarn start ``` -------------------------------- ### Install and Start Project with Yarn Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/session-keys/app/README.md Use these commands to install project dependencies and start the application using Yarn. ```bash yarn install yarn start ``` -------------------------------- ### Install and Start Project with Npm Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/session-keys/app/README.md Use these commands to install project dependencies and start the application using Npm. ```bash npm install npm run start ``` -------------------------------- ### Start with Yarn Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/anchor-counter/app/README.md Use this command to start the application after installation using Yarn. ```bash yarn start ``` -------------------------------- ### Start Project with Npm Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/anchor-counter/app/README.md Use this command to start the project after installation with npm. ```bash npm run start ``` -------------------------------- ### Install Frontend Dependencies and Start Dev Server Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/rock-paper-scissor/README.md Navigates to the app directory, installs Node.js dependencies, and starts the development server for the web UI. This is used for playing the game. ```bash cd app && yarn && yarn dev ``` -------------------------------- ### Start Project with Yarn Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/anchor-counter/app/README.md Use this command to start the project after installation with Yarn. ```bash yarn start ``` -------------------------------- ### Install and Run with npm Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/spl-tokens/app/README.md Installs project dependencies and starts the development server using npm. Ensure Node.js (18+) is installed. ```bash npm install npm run start ``` -------------------------------- ### Install and Run with yarn Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/spl-tokens/app/README.md Installs project dependencies and starts the development server using yarn. Ensure Node.js (18+) is installed. ```bash yarn install yarn start ``` -------------------------------- ### Launch Frontend Application Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/spl-tokens/README.md Navigates to the application directory, installs its dependencies, and starts the development server for the React UI. Refer to the app's README for RPC endpoint configuration. ```bash cd app yarn install yarn dev ``` -------------------------------- ### Install Frontend Dependencies Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/roll-dice/README.md Navigates to the frontend directory and installs its dependencies using Yarn. This is required before starting the development server. ```bash cd roll-dice/app yarn install ``` -------------------------------- ### Install and Run Project Dependencies Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/rock-paper-scissor/app/README.md Installs project dependencies and starts the development server. The `yarn dev` command serves the app with `--host`, enabling QR code functionality for mobile devices on the same network. ```bash yarn yarn dev ``` -------------------------------- ### Run All Examples End-to-End Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/pinocchio-ephemeral-permission-counter/README.md Builds and runs all examples in the repository end-to-end, similar to the CI process. This is a convenient command for comprehensive testing. ```bash ./test-locally.sh ``` -------------------------------- ### Install Dependencies Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/spl-tokens/app/README.md Run this command in the `app` directory to install project dependencies. ```bash npm install ``` -------------------------------- ### Install Development Tools Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/anchor-counter/README.md Installs the necessary Solana, Rust, and Anchor versions for the project. ```sh agave-install init 3.1.9 rustup install 1.89.0 avm use 1.0.2 ``` -------------------------------- ### Install Rust Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/rock-paper-scissor/README.md Installs Rust using the official script. Ensure Rust is installed before proceeding with other dependencies. ```bash curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` -------------------------------- ### Install Project with Npm Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/anchor-counter/app/README.md Use this command to install project dependencies with npm. ```bash npm run install ``` -------------------------------- ### Run Development Server Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/spl-tokens/app/README.md Execute this command to start the React development server. ```bash npm run dev ``` -------------------------------- ### Install Project Dependencies and Build Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/anchor-counter/README.md Installs project dependencies using Yarn and builds the program. ```bash yarn yarn build ``` -------------------------------- ### Run Local Tests Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/anchor-counter/README.md Executes the example's tests against the locally running MagicBlock cluster. Ensure 'yarn setup' is running in another terminal. ```bash yarn test:local ``` -------------------------------- ### Install Project with Yarn Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/anchor-counter/app/README.md Use this command to install project dependencies with Yarn. ```bash yarn install ``` -------------------------------- ### Install and Initialize Solana, Rust, and Anchor Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/dummy-token-transfer/README.md Installs and initializes specific versions of Solana, Rust, and Anchor. Ensure these versions match the project's requirements. ```sh # Check and initialize your Solana version agave-install list agave-install init 2.1.21 # Check and initialize your Rust version rustup show rustup install 1.82 # Check and initialize your Anchor version avm list avm use 0.31.1 ``` -------------------------------- ### Install and Use Anchor CLI Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/rock-paper-scissor/README.md Installs the Anchor framework and selects a specific version. Anchor is used for developing Solana programs. ```bash cargo install --git https://github.com/coral-xyz/anchor avm --locked --force avm install 0.32.1 avm use 0.32.1 ``` -------------------------------- ### Install Solana CLI Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/rock-paper-scissor/README.md Installs the Solana CLI tools. This is required for interacting with the Solana blockchain. ```bash sh -c "$(curl -sSfL https://release.anza.xyz/v2.3.13/install)" ``` -------------------------------- ### Copy Environment Configuration Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/private-counter/README.md Copy the example environment file to .env and configure your RPC endpoints for both the base layer and the Ephemeral Rollup TEE. ```bash cp .env.example .env ``` -------------------------------- ### Install Solana CLI Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/private-counter/README.md Check and initialize your Solana version using the agave-install tool. Ensure you have the correct version installed for the project. ```sh agave-install list agave-install init 2.3.13 ``` -------------------------------- ### Start Frontend Development Server Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/roll-dice/README.md Launches the frontend development server, making the application accessible locally. The application will typically run on http://localhost:3000. ```bash yarn dev ``` -------------------------------- ### Initialize Solana, Rust, and Anchor Versions Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/roll-dice/README.md Ensures the correct versions of Solana, Rust, and Anchor are installed and initialized for the project. This is a prerequisite for building and testing the application. ```sh # Check and initialize your Solana version agave-install list agave-install init 2.1.6 # Check and initialize your Rust version rustup show rustup install 1.82 # Check and initialize your Anchor version avm list avm use 0.32.1 ``` -------------------------------- ### Initialize Solana and Rust Versions Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/crank-counter/README.md Ensures the correct versions of Solana and Rust are installed and initialized for the project. This is a prerequisite for building and testing the program. ```sh # Check and initialize your Solana version agave-install list agave-install init 2.3.13 # Check and initialize your Rust version rustup show rustup install 1.85.0 ``` -------------------------------- ### Install Agave and Rust Toolchain Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/pinocchio-roll-dice/README.md Installs the specified versions of Agave and the Rust toolchain required for the project. ```sh agave-install init 3.1.9 rustup install 1.89.0 ``` -------------------------------- ### Install Rust Toolchain Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/private-counter/README.md Check and initialize your Rust version using rustup. This ensures compatibility with the project's Rust dependencies. ```sh rustup show rustup install 1.85.0 ``` -------------------------------- ### Install Anchor CLI Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/private-counter/README.md Check and initialize your Anchor version using avm. This is crucial for developing and testing Anchor programs. ```sh avm list avm use 0.32.1 ``` -------------------------------- ### Install Frontend Dependencies Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/roll-dice/README.md Installs the necessary Node.js packages for the frontend application using Yarn. This command should be executed within the 'roll-dice/app' directory. ```bash yarn install ``` -------------------------------- ### Initialize Solana, Rust, and Anchor Versions Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/magic-actions/README.md Ensures the correct versions of Solana, Rust, and Anchor are installed and initialized for the project. This is a prerequisite for building and testing the Magic Actions program. ```sh # Check and initialize your Solana version agave-install list agave-install init 2.3.13 # Check and initialize your Rust version rustup show rustup install 1.85.0 # Check and initialize your Anchor version avm list avm use 0.32.1 ``` -------------------------------- ### Start Local MagicBlock Cluster Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/anchor-counter/README.md Starts a local MagicBlock cluster including a Solana validator and Ephemeral Rollup. This command holds the cluster until a key is pressed. ```bash yarn setup ``` -------------------------------- ### Start Local Ephemeral Validator Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/dummy-token-transfer/README.md Starts the local ephemeral validator. Sets the reference RPC endpoint for accounts and specifies an ephemeral lifecycle. ```bash ACCOUNTS_REMOTE=https://rpc.magicblock.app/devnet ACCOUNTS_LIFECYCLE=ephemeral ephemeral-validator ``` -------------------------------- ### Build and Test Anchor Program Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/anchor-counter/README.md Commands to build, deploy, and test the Anchor program. The test script handles Ephemeral Rollup setup for localnet. ```bash yarn anchor test --skip-deploy --skip-build --skip-local-validator ``` ```bash # Delete keypairs in the deploy folder rm -rf /target/deploy/*.keypair # Build, deploy and test program anchor test ``` -------------------------------- ### Install Local Ephemeral Validator Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/dummy-token-transfer/README.md Installs the ephemeral validator globally using npm. This is a prerequisite for running tests with a local ephemeral rollup. ```bash npm install -g @magicblock-labs/ephemeral-validator ``` -------------------------------- ### Deploy to Localnet Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/rock-paper-scissor/README.md Deploys the Solana program to a local validator. Start the validator in a separate terminal before running this command. ```bash solana-test-validator anchor deploy --provider.cluster localnet ``` -------------------------------- ### Run Tests with Ephemeral Rollup Setup Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/ephemeral-account-chats/README.md Executes the test suite for the Anchor program, automatically configuring the Ephemeral Rollup for localnet testing. This command skips deployment and building, assuming they are handled separately or not needed for the current test run. ```bash yarn anchor test --skip-deploy --skip-build --skip-local-validator ``` -------------------------------- ### Configure RPC Endpoints with Localhost Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/spl-tokens/app/README.md Set environment variables for Solana and Ephemeral Rollup RPC endpoints when starting the application locally. Defaults are provided if these variables are not set. ```bash REACT_APP_PROVIDER_ENDPOINT=http://localhost:8899 \ REACT_APP_EPHEMERAL_PROVIDER_ENDPOINT=http://localhost:7799 \ npm run start ``` -------------------------------- ### Run MagicBlock Validator Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/crank-counter/README.md Starts the MagicBlock Validator, which is necessary for local development with Ephemeral Rollups. It connects to the Solana test validator running on `http://localhost:8899`. ```bash RUST_LOG=debug cargo run -- --remote http://localhost:8899 --listen 127.0.0.1:7799 ``` -------------------------------- ### Run Tests with Local Ephemeral Rollup Setup Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/crank-counter/README.md Executes the project tests after setting up the local Ephemeral Rollup environment. The flags ensure that deployment, local validator, and building steps are skipped as they have already been handled. ```bash anchor test --skip-deploy --skip-local-validator --skip-build ``` -------------------------------- ### Start Local Solana Test Validator Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/crank-counter/README.md Initiates a local Solana test validator. The `--reset` flag ensures a clean state for testing, which is crucial for reproducible test runs. ```bash mb-test-validator --reset ``` -------------------------------- ### Undelegate via Increment Instruction (TypeScript) Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/private-counter/README.md This example demonstrates undelegating permissions atomically with an increment operation using the `increment_and_undelegate` instruction. This is an ER transaction, not a base-layer operation. ```typescript await program.methods .incrementAndUndelegate() .accountsPartial({ payer: providerEphemeralRollup.wallet.publicKey, counter: counterPDA, }) .rpc(); ``` -------------------------------- ### Rust Delegate Macro and Account Struct Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/private-counter/README.md Defines the account struct for delegating the counter privately using the `#[delegate]` macro from the ephemeral_rollups_sdk. This setup is used for private delegation of the counter PDA. ```rust use ephemeral_rollups_sdk::{anchor::delegate, cpi::DelegateConfig}; #[delegate] #[derive(Accounts)] pub struct DelegateCounterPrivately<'info> { pub authority: Signer<'info>, #[account(mut, del, seeds = [COUNTER_SEED, authority.key().as_ref()], bump)] pub counter: AccountInfo<'info>, // ... } pub fn delegate(ctx: Context) -> Result<()> { if ctx.accounts.counter.owner != &ephemeral_rollups_sdk::id() { ctx.accounts.delegate_counter( &ctx.accounts.authority, &[COUNTER_SEED, ctx.accounts.authority.key().as_refフィック()], DelegateConfig { validator: ctx.accounts.validator.as_ref().map(|v| v.key()), ..Default::default() }, )?; } Ok(()) } ``` -------------------------------- ### Build, Deploy, and Test New Program Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/magic-actions/README.md Builds, deploys, and tests a new program, requiring the deletion of existing keypairs in the target deploy folder to ensure a clean deployment. ```bash # Delete keypairs in the deploy folder rm -rf /target/deploy/*.keypair # Build, deploy and test program anchor test ``` -------------------------------- ### Build, Deploy, and Run Tests Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/private-counter/README.md Perform a full test flow including building, deploying, and running tests. Remove existing deployment artifacts if a fresh program ID is needed. ```bash rm -rf target/deploy/*.json anchor test ``` -------------------------------- ### Build and Deploy Program to Localnet Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/crank-counter/README.md Compiles the Anchor program and deploys it to the localnet cluster. This step is necessary before running tests against the deployed program. ```bash anchor build && anchor deploy --provider.cluster localnet ``` -------------------------------- ### Build the Solana Program Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/roll-dice/README.md Compiles the Solana program using the Anchor framework. This command should be run from the project's root directory. ```bash anchor build ``` -------------------------------- ### Get Commitment Signature (TypeScript) Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/private-counter/README.md After sending a transaction to the ER, use this to obtain the base-layer commitment signature. This confirms the state commit to Solana. ```typescript import { GetCommitmentSignature } from "@magicblock-labs/ephemeral-rollups-sdk"; const erSig = await providerEphemeralRollup.sendAndConfirm(commitTx); const baseSig = await GetCommitmentSignature( erSig, providerEphemeralRollup.connection, ); ``` -------------------------------- ### Run Tests with Package Script Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/private-counter/README.md Execute the project's test script, which defaults to skipping deployment. This is a convenient shortcut for the test command. ```bash yarn test ``` -------------------------------- ### Deploy to Devnet Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/rock-paper-scissor/README.md Deploys the Solana program to the Devnet cluster. Ensure your wallet is configured and Anchor.toml is updated with the program ID. ```bash anchor deploy --provider.cluster devnet ``` -------------------------------- ### Initialize Anchor Version Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/crank-counter/README.md Manages the Anchor framework version, which is essential for developing Solana programs. Use `avm list` to see available versions and `avm use` to switch. ```sh # Check and initialize your Anchor version avm list avm use 0.32.1 ``` -------------------------------- ### Run Tests with Existing Program Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/magic-actions/README.md Executes tests for the program without deploying or building, useful for quick verification of test logic against an already deployed program. ```bash anchor test --skip-deploy --skip-build --skip-local-validator ``` -------------------------------- ### Run Tests on Devnet Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/dummy-token-transfer/README.md Executes tests on the devnet, skipping local validator, build, and deploy steps. Requires devnet SOL in your local wallet. ```bash anchor test --skip-local-validator --skip-build --skip-deploy ``` -------------------------------- ### Run Web3.js Tests Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/oncurve-delegation/README.md Executes the parallel web3.js implementation of the delegation workflow against the configured endpoints. ```bash yarn test:web3js ``` -------------------------------- ### Configure Environment Variables for Local Development Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/crank-counter/README.md Sets up essential environment variables required for local development with Ephemeral Rollups. These variables define endpoints for the Ephemeral provider and WebSocket, as well as Solana wallet and RPC configurations. ```bash export EPHEMERAL_PROVIDER_ENDPOINT=http://localhost:7799 export EPHEMERAL_WS_ENDPOINT=ws://localhost:7800 export ANCHOR_WALLET=${HOME}/.config/solana/id.json export ANCHOR_PROVIDER_URL="http://127.0.0.1:8899" ``` -------------------------------- ### Delegate Account using Rust CPI Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/anchor-counter/README.md Rust code demonstrating how to delegate an account using CPI to the delegation program. This allows low-latency transactions on the delegated account. ```rust use ephemeral_rollups_sdk::cpi::delegate_account; use ephemeral_rollups_sdk::er::commit_accounts; use ephemeral_rollups_sdk::anchor::delegate; #[delegate] #[program] pub mod anchor_counter { pub fn delegate(ctx: Context) -> Result<()> { let pda_seeds: &[&[u8]] = &[TEST_PDA_SEED]; delegate_account( &ctx.accounts.payer, &ctx.accounts.pda, &ctx.accounts.owner_program, &ctx.accounts.buffer, &ctx.accounts.delegation_record, &ctx.accounts.delegate_account_seeds, &ctx.accounts.delegation_program, &ctx.accounts.system_program, pda_seeds, 0, // max delegation lifetime, 0 means no limit 30000, // commit interval in ms (30s) )?; Ok(()) } } ``` -------------------------------- ### Run Stress Test Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/rewards-delegated-vrf/README.md Executes a stress test that makes 100 repeated VRF requests to exercise the system. This is useful for performance and stability testing. ```bash yarn test:stress ``` -------------------------------- ### Initialize Session Signer and Token Manager Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/session-keys/README.md TypeScript code for initializing a session keypair and a SessionTokenManager using the Gum SDK. This is used on the client-side to manage session tokens and sign transactions. ```typescript import { SessionTokenManager } from "@magicblock-labs/gum-sdk"; const sessionKeypair = initializeSessionSignerKeypair(); const sessionTokenManager = new SessionTokenManager( provider.wallet, provider.connection, ); ``` -------------------------------- ### Delegate Account using Rust CPI Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/anchor-counter/README.md Marks a program with #[delegate] and uses CPI to call the delegate instruction of the delegation program. This enables low-latency transactions on the delegated account. ```rust use ephemeral_rollups_sdk::cpi::delegate_account; use ephemeral_rollups_sdk::er::commit_accounts; use ephemeral_rollups_sdk::anchor::delegate; #[delegate] #[program] pub mod anchor_counter { pub fn delegate(ctx: Context) -> Result<()> { let pda_seeds: &[&[u8]] = &[TEST_PDA_SEED]; delegate_account( &ctx.accounts.payer, &ctx.accounts.pda, &ctx.accounts.owner_program, &ctx.accounts.buffer, &ctx.accounts.delegation_record, &ctx.accounts.delegate_account_seeds, &ctx.accounts.delegation_program, &ctx.accounts.system_program, pda_seeds, 0, // max delegation lifetime, 0 means no limit 30000, // commit interval in ms (30s) )?; Ok(()) } } ``` -------------------------------- ### Run Tests with Local Ephemeral Validator Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/dummy-token-transfer/README.md Executes tests while connected to a local ephemeral validator. Points to the local validator's RPC and WebSocket endpoints and skips build, deploy, and local validator steps. ```bash PROVIDER_ENDPOINT=http://localhost:8899 WS_ENDPOINT=ws://localhost:8900 anchor test --skip-build --skip-deploy --skip-local-validator ``` -------------------------------- ### Run Tests with Custom Ephemeral Endpoint Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/rock-paper-scissor/README.md Runs the test suite against a custom ephemeral rollup endpoint. Set the EPHEMERAL_PROVIDER_ENDPOINT and EPHEMERAL_WS_ENDPOINT environment variables. ```bash EPHEMERAL_PROVIDER_ENDPOINT=http://your-endpoint:port \ EPHEMERAL_WS_ENDPOINT=ws://your-endpoint:port \ yarn test ``` -------------------------------- ### Rust Session Authorization Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/session-keys/README.md Rust code demonstrating session key authorization for a counter program. It uses `#[session_auth_or(...)]` to allow authorization by either the counter authority or a valid `SessionTokenV2`. ```rust use session_keys::{session_auth_or, Session, SessionError, SessionTokenV2}; #[session_auth_or( ctx.accounts.counter.authority.key() == ctx.accounts.payer.key(), SessionError::InvalidToken )] pub fn increment(ctx: Context) -> Result<()> { let counter = &mut ctx.accounts.counter; counter.count += 1; Ok(()) } ``` -------------------------------- ### Build and Generate Types Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/rock-paper-scissor/README.md Compile the Anchor program and regenerate TypeScript types after making changes to the program logic. Ensure you run `anchor build` to update the types. ```bash anchor build --skip-lint ``` -------------------------------- ### Add Ephemeral Rollups SDK for Rust Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/anchor-counter/README.md Command to add the ephemeral-rollups-sdk to your Rust project's dependencies. ```bash cargo add ephemeral-rollups-sdk ``` -------------------------------- ### Derive Permission PDA (TypeScript) Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/private-counter/README.md Derive the permission PDA from a counter account using the TypeScript SDK. This is a prerequisite for initializing a permission. ```typescript import { permissionPdaFromAccount, MAGIC_PROGRAM_ID, PERMISSION_PROGRAM_ID, } from "@magicblock-labs/ephemeral-rollups-sdk"; const permissionPDA = permissionPdaFromAccount(counterPDA); await program.methods .initializePermission() .accountsPartial({ counter: counterPDA, permission: permissionPDA, magicProgram: MAGIC_PROGRAM_ID, permissionProgram: PERMISSION_PROGRAM_ID, ephemeralVault: VAULT_ID, }) .rpc(); ``` -------------------------------- ### Add Ephemeral Rollups SDK for TypeScript Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/anchor-counter/README.md Command to add the ephemeral-rollups-sdk to your TypeScript project's dependencies. ```bash yarn add @magicblock-labs/ephemeral-rollups-sdk ``` -------------------------------- ### Commit and Undelegate Transaction Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/rust-counter/README.md Use this snippet to create, send, and confirm a transaction for committing and undelegating an account. Ensure you have the necessary keys and program IDs set up. ```typescript // 3: CommitAndUndelegate // Create, send and confirm transaction const tx = new web3.Transaction(); const keys = [ // Initializer { pubkey: userKeypair.publicKey, isSigner: true, isWritable: true, }, // Counter Account { pubkey: counterPda, isSigner: false, isWritable: true, }, // Magic Program { pubkey: MAGIC_PROGRAM_ID, isSigner: false, isWritable: false, }, // Magic Context { pubkey: MAGIC_CONTEXT_ID, isSigner: false, isWritable: true, }, ]; const serializedInstructionData = Buffer.from([ CounterInstruction.CommitAndUndelegate, ]); const initializeIx = new web3.TransactionInstruction({ keys: keys, programId: PROGRAM_ID, data: serializedInstructionData, }); tx.add(initializeIx); const txHash = await web3.sendAndConfirmTransaction( connectionEphemeralRollup, // "https://devnet.magicblock.app/" or "http://localhost:8899" tx, [userKeypair], { skipPreflight: true, commitment: "confirmed", } ); console.log("txId:", txHash); ``` -------------------------------- ### Create Ephemeral Permission (Rust) Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/private-counter/README.md Use this snippet to create an ephemeral permission on the ER. It requires the payer, permissioned account, and permission details, setting `is_private` to true. ```rust CreateEphemeralPermissionCpi { payer: ctx.accounts.counter.to_account_info(), permissioned_account: ctx.accounts.counter.to_account_info(), permission: ctx.accounts.permission.to_account_info(), // ... args: EphemeralMembersArgs { is_private: true, members: vec![Member { flags: TX_LOGS_FLAG | TX_MESSAGE_FLAG | TX_BALANCES_FLAG, pubkey: ctx.accounts.counter.authority, }], }, } .invoke_signed(&[&signers])?; ``` -------------------------------- ### Execute Increment Transaction using TypeScript SDK Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/anchor-counter/README.md TypeScript code to execute an increment transaction on a delegated account. This involves constructing the transaction, setting fee payer and recent blockhash, signing, and sending. ```typescript let tx = await program.methods .increment() .accounts({ counter: pda, }) .transaction(); tx.feePayer = providerEphemeralRollup.wallet.publicKey; tx.recentBlockhash = ( await providerEphemeralRollup.connection.getLatestBlockhash() ).blockhash; tx = await providerEphemeralRollup.wallet.signTransaction(tx); const txSign = await providerEphemeralRollup.sendAndConfirm(tx, []); console.log("Increment Tx: ", txSign); ``` -------------------------------- ### Execute Increment Transaction on ER (TypeScript) Source: https://github.com/magicblock-labs/magicblock-engine-examples/blob/main/00-LEGACY_EXAMPLES/private-counter/README.md This snippet shows how to construct, sign, and send an increment transaction to the Ephemeral Rollup. Ensure you have an `AnchorProvider` connected to the TEE endpoint. ```typescript let tx = await program.methods .increment() .accounts({ counter: counterPDA }) .transaction(); tx.feePayer = providerEphemeralRollup.wallet.publicKey; tx.recentBlockhash = ( await providerEphemeralRollup.connection.getLatestBlockhash() ).blockhash; tx = await providerEphemeralRollup.wallet.signTransaction(tx); const sig = await providerEphemeralRollup.sendAndConfirm(tx); ```