trezoa-system-interface

Crates.iotrezoa-system-interface
lib.rstrezoa-system-interface
version3.2.2
created_at2025-10-31 21:30:25.011261+00
updated_at2025-11-05 14:18:10.75006+00
descriptionInstructions and constructors for the System program
homepagehttps://trezoa.xyz/
repositoryhttps://github.com/Trezoa-team/trezoa-system-interface
max_upload_size
id1910833
size123,291
(TRZLedgerFoundation)

documentation

README

Trezoa System Interface

This crate contains instructions and constructors for interacting with the System program.

The System program can be used to create new accounts, allocate account data, assign accounts to owning programs, transfer lamports from System Program owned accounts and pay transaction fees.

Getting Started

From your project folder:

cargo add trezoa-system-interface --features bincode

This will add the trezoa-system-interface dependency with the bincode feature enabled to your Cargo.toml file. The bincode feature contains the instruction constructors to create instructions for the System program.

Examples

Creating an account:

use trezoa_rpc_client::rpc_client::RpcClient;
use trezoa_sdk::{
    signature::{Keypair, Signer},
    transaction::Transaction,
};
use trezoa_system_interface::instruction;
use anyhow::Result;

fn create_account(
    client: &RpcClient,
    payer: &Keypair,
    new_account: &Keypair,
    owning_program: &Pubkey,
    space: u64,
) -> Result<()> {
    let rent = client.get_minimum_balance_for_rent_exemption(space.try_into()?)?;
    let instr = instruction::create_account(
        &payer.pubkey(),
        &new_account.pubkey(),
        rent,
        space,
        owning_program,
    );

    let blockhash = client.get_latest_blockhash()?;
    let tx = Transaction::new_signed_with_payer(
        &[instr],
        Some(&payer.pubkey()),
        &[payer, new_account],
        blockhash,
    );

    let _sig = client.send_and_confirm_transaction(&tx)?;

    Ok(())
}

Transfer lamports between accounts:

use trezoa_rpc_client::rpc_client::RpcClient;
use trezoa_pubkey::Pubkey;
use trezoa_sdk::{
    signature::{Keypair, Signer},
    transaction::Transaction,
};
use trezoa_system_interface::instruction;
use anyhow::Result;

fn transfer(
    client: &RpcClient,
    from: &Keypair,
    recipient: &Pubkey,
    lamports: u64,
) -> Result<()> {
    let instr = instruction::transfer(
        &from.pubkey(),
        recipient,
        lamports,
    );

    let blockhash = client.get_latest_blockhash()?;
    let tx = Transaction::new_signed_with_payer(
        &[instr],
        Some(&from.pubkey()),
        &[from],
        blockhash,
    );

    let _sig = client.send_and_confirm_transaction(&tx)?;

    Ok(())
}

More examples can be found on the crate documentation.

Commit count: 0

cargo fmt