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
| Name | Required | Type | Description |
|---|---|---|---|
idl_path | required | string | The path, relative to the txtx.yml, to the IDL .json file |
instruction_name | required | string | The name of the instruction to generate data for |
arguments | optional | array[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
| Name | Required | Type | Description |
|---|---|---|---|
idl | required | string | SVM_IDL | The program IDL |
instruction_name | required | string | The name of the instruction to generate data for, as indexed by the IDL |
arguments | optional | array[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
| Name | Required | Type | Description |
|---|---|---|---|
program_name | required | string | The name of the program being deployed |
keypair_path | optional | string | The location of the program keypair file |
idl_path | optional | string | The location of the program IDL file |
bin_path | optional | string | The 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
| Name | Required | Type | Description |
|---|---|---|---|
program_name | required | string | The name of the program being deployed |
keypair_path | optional | string | The location of the program keypair file |
idl_path | optional | string | The location of the program IDL file |
bin_path | optional | string | The 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
| Name | Required | Type | Description |
|---|---|---|---|
program_id | required | string | The address of the program the PDA is derived from |
seeds | optional | array[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
| Name | Required | Type | Description |
|---|---|---|---|
wallet_address | required | string | The address of the wallet |
token_mint_address | optional | string | The 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
| Name | Required | Type | Description |
|---|---|---|---|
funding_address | required | string | The address of the funding account |
wallet_address | required | string | The address of the wallet |
token_mint_address | optional | string | The address of the token mint |
token_program_id | optional | string | The 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 addresssigner.caller.address, // wallet addressvariable.token_mint, // token mint addressvariable.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
| Name | Required | Type | Description |
|---|---|---|---|
value | required | integer | The 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
| Name | Required | Type | Description |
|---|---|---|---|
value | required | integer | The i64 integer to convert to a byte array |
variable "pda" {value = svm::find_pda("3bv3j4GvMPjvvBX9QdoX27pVoWhDSXpwKZipFF1QiVr6", [svm::i64(-1000000000)])}
Is this page helpful?