#toolbox #endpoint #solana #rpc-client #account #transaction #built-in

solana_toolbox_endpoint

Toolbox for interacting with an arbitrary solana endpoint

61 releases

0.1.38-solana-2.1.4 Jan 29, 2025
0.1.37-solana-2.1.4 Jan 27, 2025
0.1.13-solana-1.18.26 Dec 31, 2024

#13 in #builtin

Download history 622/week @ 2024-12-23 768/week @ 2024-12-30 2431/week @ 2025-01-06 649/week @ 2025-01-13 1079/week @ 2025-01-20 691/week @ 2025-01-27 110/week @ 2025-02-03 43/week @ 2025-02-10

2,101 downloads per month
Used in 2 crates

MIT license

140KB
2K SLoC

Contains (ELF lib, 315KB) UCNcQRtrbGmvuLKA3Jv719Cc6DS4r661ZRpyZduxu2j.so, (ELF lib, 20KB) bpf_loader_program_minimal.so

Solana Toolbox Endpoint

Abstract

This crate provide boilerplate types to enable writing endpoint-independent code that interact interchangebly with:

  • mainnet-meta (using an RpcClient internally)
  • devnet (using an RpcClient internally)
  • testnet (using an RpcClient internally)
  • localnet (using an RpcClient internally)
  • memnet (using a ProgramTest mocked Solana runtime)

The same code can then be run on a different cluster or a different runtime, just by swapping the ToolboxEndpoint object

Install

Make sure to install the version that matches your solana version. Each solana version may come with a different set of dependency hell, so you can specify the solana version you're using directly in the version of this crate.

in Cargo.toml:

# For example when using solana version 1.18.26"
solana_toolbox_endpoint = "=0.1.38-solana-1.18.26"
# Or when using solana version 2.1.4"
solana_toolbox_endpoint = "=0.1.38-solana-2.1.4"

Examples

The main type that we will be using is the ToolboxEndpoint that can be initialized from many different types of runtimes/RPCs.

This ToolboxEndpoint type then expose capabilities to fetch accounts, execute transactions and a lot of useful boilerplate utilities.

How to create an endpoint object:

// First we create an endpoint object (here we use "program_test" or "memnet")
let mut endpoint = ToolboxEndpoint::new_program_test_with_builtin_programs(&[
    toolbox_endpoint_program_test_builtin_program_anchor!(
        "my_smart_contract",
        my_smart_contract::ID,
        my_smart_contract::entry
    ),
])
.await;
// Alternatively We can create an endpoint that uses devnet instead
let mut endpoint = ToolboxEndpoint::new_rpc_with_url_and_commitment(
    "https://api.devnet.solana.com",
    CommitmentConfig::confirmed(),
);
// Optionally make the endpoint print all transaction/fetching
endpoint.add_logger(Box::new(ToolboxEndpointLoggerPrinter::default()));

Then we can use our endpoint previously created:

// The endpoint object provides a lot of useful boilerplate utility functions
endpoint
    .process_system_transfer(
        &payer,
        &source,
        &destination.pubkey(),
        1_000_000_000,
    )
    .await
    .unwrap();
// Then we can use the endpoint to run arbitrary transaction instructions
endpoint
    .process_instruction(
        Instruction {
            program_id: my_smart_contract::ID,
            accounts: vec![],
            data: vec![],
        },
        &payer,
    )
    .await
    .unwrap();

Documentation

See the docs for the exhaustive list of the ToolboxEndpoint capabilities:

Dependencies

~96MB
~2M SLoC