Infrastructure as CodeSVM Addon

SVM Functions

Functions for Solana and SVM Compatible Blockchains

These functions are available when using the SVM addon for Solana and SVM-compatible blockchains.

system_program_id

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

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

default_pubkey

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

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

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

NameRequiredTypeDescription
idl_pathrequiredstringThe path, relative to the txtx.yml, to the IDL .json file
instruction_namerequiredstringThe name of the instruction to generate data for
argumentsoptionalarray[string]The instruction arguments to generate data for
output "data" {
    value = svm::get_instruction_data_from_idl("/path/to/idl.json", "my_instruction", ["arg1", "arg2"])
}
// > data: 0x95763bdcc47fa1b305000000776f726c64

get_instruction_data_from_idl

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

Inputs

NameRequiredTypeDescription
idlrequiredstring | SVM_IDLThe program IDL
instruction_namerequiredstringThe name of the instruction to generate data for, as indexed by the IDL
argumentsoptionalarray[string]The instruction arguments to generate data for
output "data" {
    value = svm::get_instruction_data_from_idl(variable.contract.idl, "my_instruction", ["arg1", "arg2"])
}
// > data: 0x95763bdcc47fa1b305000000776f726c64

get_program_from_anchor_project

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

Inputs

NameRequiredTypeDescription
program_namerequiredstringThe name of the program being deployed
keypair_pathoptionalstringThe location of the program keypair file
idl_pathoptionalstringThe location of the program IDL file
bin_pathoptionalstringThe location of the program binary file
variable "contract" {
    value = svm::get_program_from_anchor_project("my_program")
}
output "idl" {
    value = variable.contract.idl
}

get_program_from_native_project

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

Inputs

NameRequiredTypeDescription
program_namerequiredstringThe name of the program being deployed
keypair_pathoptionalstringThe location of the program keypair file
idl_pathoptionalstringThe location of the program IDL file
bin_pathoptionalstringThe location of the program binary file
variable "contract" {
    value = svm::get_program_from_native_project("my_program")
}
output "idl" {
    value = variable.contract.idl
}

sol_to_lamports

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

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

lamports_to_sol

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

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

find_pda

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

Inputs

NameRequiredTypeDescription
program_idrequiredstringThe address of the program the PDA is derived from
seedsoptionalarray[string]An optional array of seeds (max 16, 32 bytes each)
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

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

NameRequiredTypeDescription
wallet_addressrequiredstringThe address of the wallet
token_mint_addressoptionalstringThe address of the token mint
variable "token_account" {
    value = svm::get_associated_token_account(signer.caller.address, "So11111111111111111111111111111111111111112")
}

create_token_account_instruction

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

Inputs

NameRequiredTypeDescription
funding_addressrequiredstringThe address of the funding account
wallet_addressrequiredstringThe address of the wallet
token_mint_addressoptionalstringThe address of the token mint
token_program_idoptionalstringThe address of the token program
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
        )
    }
}

u64

svm::u64 creates a byte array representation of a u64 integer, suitable for use as a seed in PDA derivation.

Inputs

NameRequiredTypeDescription
valuerequiredintegerThe u64 integer to convert to a byte array
variable "pda" {
    value = svm::find_pda("3bv3j4GvMPjvvBX9QdoX27pVoWhDSXpwKZipFF1QiVr6", [svm::u64(1000000000)])
}

i64

svm::i64 creates a byte array representation of an i64 integer, suitable for use as a seed in PDA derivation.

Inputs

NameRequiredTypeDescription
valuerequiredintegerThe i64 integer to convert to a byte array
variable "pda" {
    value = svm::find_pda("3bv3j4GvMPjvvBX9QdoX27pVoWhDSXpwKZipFF1QiVr6", [svm::i64(-1000000000)])
}

On this page