#transaction #instructions #blockchain #solana #tpu

jib

Jib is a library for the Solana blockchain that lets you efficiently pack instructions into transactions and submit them via a TPU client

8 breaking releases

0.9.0 Mar 24, 2024
0.7.0 Jan 9, 2024
0.5.0 Dec 20, 2023
0.4.1 Sep 27, 2023

#7 in #tpu

Download history 190/week @ 2024-03-11 302/week @ 2024-03-18 163/week @ 2024-03-25 125/week @ 2024-04-01 100/week @ 2024-04-08 81/week @ 2024-04-15 64/week @ 2024-04-22 24/week @ 2024-04-29 44/week @ 2024-05-06 39/week @ 2024-05-13 64/week @ 2024-05-20 88/week @ 2024-05-27 45/week @ 2024-06-03 55/week @ 2024-06-10 52/week @ 2024-06-17 43/week @ 2024-06-24

204 downloads per month
Used in metaboss

Apache-2.0

39KB
661 lines

Crate Downloads License

Jib

Jib is a simple Rust library that efficiently packs a vector of Solana instructions into maximum size and account length transactions and then sends them over the network. It can be used with a RPC node to send the transactions async using Tokio green threads or with a TPU client which will send the transactions to the current leader and confirm them. It also has the ability to retry failed transactions and pack them into new transactions.

Example Usage

In this example we load a list of mint accounts we want to update the metadata for, and then we create a vector of instructions with the update_metadata_accounts_v2 instruction for each mint. We then pass this vector of instructions to Jib and it will pack them into the most efficient transactions possible and send them to the network.

fn main() -> Result<()> {
    // Load our keypair file.
    let keypair = solana_sdk::signature::read_keypair_file("keypair.json").unwrap();

    // Initialize Jib with our keypair and desired network.
    let mut jib = Jib::new(vec![keypair], "https://frosty-forest-fields.solana-mainnet.quiknode.pro")?;

    let mut instructions = vec![];

    // Load mint addresses from a file.
    let addresses: Vec<String> =
        serde_json::from_reader(std::fs::File::open("collection_mints.json")?)?;

    // Create an instruction for each mint.
    for address in addresses {
        let metadata = derive_metadata_pda(&Pubkey::from_str(&address).unwrap());

        let ix = update_metadata_accounts_v2(
            mpl_token_metadata::ID,
            metadata,
            // Jib takes the payer by value but we can access it via this fn.
            jib.payer().pubkey(),
            None,
            None,
            Some(true),
            None,
        );

        instructions.push(ix);
    }

    // Set the instructions to be executed.
    jib.set_instructions(instructions);

    // Run it.
    let results = jib.hoist()?;

    // Do something with the results.
    for result in results {
        if result.is_success() {
            println!("Success: {}", result.signature().unwrap());
        } else {
            println!("Failure: {}", result.error().unwrap());
        }
    }

    Ok(())
}

Dependencies

~57–76MB
~1.5M SLoC