Solana and SVM Compatible Blockchains (beta) Functions
system_program_id
svm::system_program_id
returns the id of the system program, 11111111111111111111111111111111
.
Inputs
Output
- Name
value
- Description
The system program id.
Example using system_program_id
output "system_program_id" {
value = svm::system_program_id()
}
// > 11111111111111111111111111111111
default_pubkey
svm::default_pubkey
returns a default public key, 11111111111111111111111111111111
.
Inputs
Output
- Name
value
- Description
The default public key,
11111111111111111111111111111111
Example using default_pubkey
output "default_pubkey" {
value = svm::default_pubkey()
}
// > 11111111111111111111111111111111
account
svm::account
encodes a public key in to an account meta object for a program instruction call.
Inputs
- Name
public_key
- Description
The on-chain address of an account.
- Name
is_signer
- Description
Specify if the account is required as a signer on the transaction.
- Name
is_writable
- Description
Specify if the account data will be modified.
Output
- Name
value
- Description
The account meta object.
Example using account
output "account" {
value = svm::account("3z9vL1zjN6qyAFHhHQdWYRTFAcy69pJydkZmSFBKHg1R", true, true)
}
// > account: { public_key: 3z9vL1zjN6qyAFHhHQdWYRTFAcy69pJydkZmSFBKHg1R, is_signer: true, is_writable: true }
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
- Description
The path, relative to the txtx.yml, to the IDL
.json
file.
- Name
instruction_name
- Description
The name of the instruction to generate data for, as indexed by the IDL.
- Name
arguments
- Description
The instruction arguments to generate data for.
Output
- Name
value
- 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
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
- Description
The program IDL.
- Name
instruction_name
- Description
The name of the instruction to generate data for, as indexed by the IDL.
- Name
arguments
- Description
The instruction arguments to generate data for.
Output
- Name
value
- 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
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
- Description
The name of the program being deployed.
- Name
target_path
- Description
The target path to the compiled anchor project artifacts. Defaults to
./target
.
Output
- Name
value
- Description
An object containing the anchor program artifacts.
Example using get_program_from_anchor_project
variable "contract" {
value = evm::get_program_from_anchor_project("my_program")
}
output "idl" {
value = variable.contract.idl
}
sol_to_lamports
svm::sol_to_lamports
converts the provided SOL amount to lamports.
Inputs
- Name
sol_amount
- Description
The amount of SOL to convert to lamports.
Output
- Name
value
- 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
lamports_to_sol
svm::lamports_to_sol
converts the provided number of lamports amount to SOL.
Inputs
- Name
lamports_amount
- Description
The amount of lamports to convert to SOL.
Output
- Name
value
- 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
find_pda
svm::find_pda
finds a valid pda using the provided program id and seeds.
Inputs
- Name
program_id
- Description
The address of the program the PDA is derived from.
- Name
seeds
- 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
- 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