Solana and SVM Compatible Blockchains (beta) Functions

function

system_program_id

svm::system_program_id returns the id of the system program, 11111111111111111111111111111111.

Inputs

    None

Output

  • Name
    value
    Type
    addon(svm::pubkey)
    Description

    The system program id.

Example using system_program_id

output "system_program_id" { 
    value = svm::system_program_id()
}
// > 11111111111111111111111111111111


function

default_pubkey

svm::default_pubkey returns a default public key, 11111111111111111111111111111111.

Inputs

    None

Output

  • Name
    value
    Type
    addon(svm::pubkey)
    Description

    The default public key, 11111111111111111111111111111111

Example using default_pubkey

output "default_pubkey" { 
    value = svm::default_pubkey()
}
// > 11111111111111111111111111111111


function

get_instruction_data_from_idl_path

svm::get_instruction_data_from_idl_path creates encoded instruction data for a program invocation, providing type checking and serialization based on the provided IDL file.

Inputs

  • Name
    idl_path
    Required
    required
    Type
    string
    Description

    The path, relative to the txtx.yml, to the IDL .json file.

  • Name
    instruction_name
    Required
    required
    Type
    string
    Description

    The name of the instruction to generate data for, as indexed by the IDL.

  • Name
    arguments
    Required
    optional
    Type
    array[string]
    Description

    The instruction arguments to generate data for.

Output

  • Name
    value
    Type
    buffer
    Description

    The encoded instruction data.

Example using get_instruction_data_from_idl_path

output "data" {
    value = svm::get_instruction_data_from_idl("/path/to/idl.json", "my_instruction", ["arg1", "arg2"])
}
// > data: 0x95763bdcc47fa1b305000000776f726c64


function

get_instruction_data_from_idl

svm::get_instruction_data_from_idl_path creates encoded instruction data for a program invocation, providing type checking and serialization based on the provided IDL data.

Inputs

  • Name
    idl
    Required
    required
    Type
    addon(svm::idl) | string
    Description

    The program IDL.

  • Name
    instruction_name
    Required
    required
    Type
    string
    Description

    The name of the instruction to generate data for, as indexed by the IDL.

  • Name
    arguments
    Required
    optional
    Type
    array[string]
    Description

    The instruction arguments to generate data for.

Output

  • Name
    value
    Type
    buffer
    Description

    The encoded instruction data.

Example using get_instruction_data_from_idl

output "data" {
    value = svm::get_instruction_data_from_idl(variable.idl, "my_instruction", ["arg1", "arg2"])
}
// > data: 0x95763bdcc47fa1b305000000776f726c64


function

get_program_from_anchor_project

svm::get_program_from_anchor_project retrieves the program deployment artifacts for a program in an Anchor project.

Inputs

  • Name
    program_name
    Required
    required
    Type
    string
    Description

    The name of the program being deployed.

  • Name
    keypair_path
    Required
    optional
    Type
    string | null
    Description

    The location of the program keypair file. Defaults to ./target/deploy/<program_name>-keypair.json.

  • Name
    idl_path
    Required
    optional
    Type
    string | null
    Description

    The location of the program IDL file. Defaults to ./target/idl/<program_name>.json.

  • Name
    bin_path
    Required
    optional
    Type
    string | null
    Description

    The location of the program binary file. Defaults to ./target/deploy/<program_name>.so.

Output

  • Name
    value
    Type
    object
    Description

    An object containing the anchor program artifacts.

Example using get_program_from_anchor_project

variable "contract" {
    value = svm::get_program_from_anchor_project("my_program")
}
output "idl" {
    value = variable.contract.idl
}    


function

get_program_from_native_project

svm::get_program_from_native_project retrieves the program deployment artifacts for a non-Anchor program.

Inputs

  • Name
    program_name
    Required
    required
    Type
    string
    Description

    The name of the program being deployed.

  • Name
    keypair_path
    Required
    optional
    Type
    string | null
    Description

    The location of the program keypair file. Defaults to ./target/deploy/<program_name>-keypair.json.

  • Name
    idl_path
    Required
    optional
    Type
    string | null
    Description

    The location of the program IDL file. Defaults to ./idl/<program_name>.json.

  • Name
    bin_path
    Required
    optional
    Type
    string | null
    Description

    The location of the program binary file. Defaults to ./target/deploy/<program_name>.so.

Output

  • Name
    value
    Type
    object
    Description

    An object containing the native program artifacts.

Example using get_program_from_native_project

variable "contract" {
    value = svm::get_program_from_native_project("my_program")
}
output "idl" {
    value = variable.contract.idl
}


function

sol_to_lamports

svm::sol_to_lamports converts the provided SOL amount to lamports.

Inputs

  • Name
    sol_amount
    Required
    required
    Type
    integer | float
    Description

    The amount of SOL to convert to lamports.

Output

  • Name
    value
    Type
    integer
    Description

    The amount of SOL provided, represented as lamports.

Example using sol_to_lamports

output "lamports" {
    value = svm::sol_to_lamports(1.1)
}
// lamports: 1100000000


function

lamports_to_sol

svm::lamports_to_sol converts the provided number of lamports amount to SOL.

Inputs

  • Name
    lamports_amount
    Required
    required
    Type
    integer
    Description

    The amount of lamports to convert to SOL.

Output

  • Name
    value
    Type
    float
    Description

    The number of lamports provided, represented as SOL.

Example using lamports_to_sol

output "sol" {
    value = svm::lamports_to_sol(1100000000)
}
// sol: 1.1


function

find_pda

svm::find_pda finds a valid pda using the provided program id and seeds.

Inputs

  • Name
    program_id
    Required
    required
    Type
    string | addon(svm::pubkey) | addon(svm::address)
    Description

    The address of the program the PDA is derived from.

  • Name
    seeds
    Required
    optional
    Type
    array[string]
    Description

    An optional array of seeds that will be used to derive the PDA. A maximum of 16 seeds can be used, and each seed can have a maximum length of 32 bytes.

Output

  • Name
    value
    Type
    object
    Description

    An object containing the PDA address and associated bump seed.

Example using find_pda

variable "pda" {
    value = svm::find_pda("3bv3j4GvMPjvvBX9QdoX27pVoWhDSXpwKZipFF1QiVr6", ["data"])
}
output "pda" {
    value = std::encode_base58(variable.pda.pda)
}
output "bump" {
    value = variable.pda.bump_seed
}
// > pda: 4amHoWMBgLkPfM8Nq9ZP33Liq9FCuqrLoU1feejkdsUJ
// > bump: 252


function

get_associated_token_account

svm::get_associated_token_account computes the address of the associated token account for the provided wallet and token mint addresses.

Inputs

  • Name
    wallet_address
    Required
    required
    Type
    string | addon(svm::pubkey) | addon(svm::address)
    Description

    The address of the wallet to compute the associated token account for.

  • Name
    token_mint_address
    Required
    optional
    Type
    string | addon(svm::pubkey) | addon(svm::address)
    Description

    The address of the token mint used to compute the token account.

Output

  • Name
    value
    Type
    addon(svm::pubkey)
    Description

    The address of the associated token account.

Example using get_associated_token_account

variable "token_account" {
    value = svm::get_associated_token_account(signer.caller.address, "So11111111111111111111111111111111111111112")
}


function

create_token_account_instruction

svm::create_token_account_instruction creates raw instruction bytes to create an associated token account.

Inputs

  • Name
    funding_address
    Required
    required
    Type
    string | addon(svm::pubkey) | addon(svm::address)
    Description

    The address of the funding account.

  • Name
    wallet_address
    Required
    required
    Type
    string | addon(svm::pubkey) | addon(svm::address)
    Description

    The address of the wallet to compute the associated token account for.

  • Name
    token_mint_address
    Required
    optional
    Type
    string | addon(svm::pubkey) | addon(svm::address)
    Description

    The address of the token mint used to compute the token account.

  • Name
    token_program_id
    Required
    optional
    Type
    string | addon(svm::pubkey) | addon(svm::address)
    Description

    The address of the token program used to compute the token account.

Output

  • Name
    value
    Type
    addon(svm::pubkey)
    Description

    The serialized instruction bytes.

Example using create_token_account_instruction

action "call" "svm::process_instructions" {
    signers = [signer.caller]

    instruction { 
        raw_bytes = svm::create_token_account_instruction(
            signer.caller.address, // funding address
            signer.caller.address, // wallet address
            variable.token_mint, // token mint address
            variable.token_program // token program id
        )
    }
}


Was this page helpful?