Các hàm này khả dụng khi sử dụng addon SVM cho Solana và các blockchain tương thích SVM.
system_program_id
svm::system_program_id trả về id của System Program,
11111111111111111111111111111111.
output "system_program_id" {value = svm::system_program_id()}// > 11111111111111111111111111111111
default_pubkey
svm::default_pubkey trả về một pubkey mặc định,
11111111111111111111111111111111.
output "default_pubkey" {value = svm::default_pubkey()}// > 11111111111111111111111111111111
get_instruction_data_from_idl_path
svm::get_instruction_data_from_idl_path tạo instruction data được mã hóa cho
một lần gọi chương trình, cung cấp khả năng kiểm tra kiểu và tuần tự hóa dựa
trên tệp IDL được cung cấp.
Đầu vào
| Name | Required | Type | Description |
|---|---|---|---|
idl_path | required | string | Đường dẫn, tương đối với txtx.yml, đến tệp IDL .json |
instruction_name | required | string | Tên của lệnh cần tạo dữ liệu |
arguments | optional | array[string] | Các đối số của lệnh cần tạo dữ liệu |
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 tạo instruction data được mã hóa cho một
lần gọi chương trình, cung cấp khả năng kiểm tra kiểu và tuần tự hóa dựa trên dữ
liệu IDL được cung cấp.
Đầu vào
| Name | Required | Type | Description |
|---|---|---|---|
idl | required | string | SVM_IDL | IDL của chương trình |
instruction_name | required | string | Tên của lệnh cần tạo dữ liệu, theo chỉ mục trong IDL |
arguments | optional | array[string] | Các đối số của lệnh cần tạo dữ liệu |
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 truy xuất các artifact triển khai chương
trình cho một chương trình trong dự án Anchor.
Đầu vào
| Tên | Bắt buộc | Kiểu | Mô tả |
|---|---|---|---|
program_name | bắt buộc | string | Tên của chương trình đang được triển khai |
keypair_path | tùy chọn | string | Vị trí của tệp keypair chương trình |
idl_path | tùy chọn | string | Vị trí của tệp IDL chương trình |
bin_path | tùy chọn | string | Vị trí của tệp nhị phân chương trình |
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 truy xuất các tệp artifact triển khai
chương trình cho một chương trình không phải Anchor.
Đầu vào
| Tên | Bắt buộc | Kiểu | Mô tả |
|---|---|---|---|
program_name | bắt buộc | string | Tên của chương trình đang được triển khai |
keypair_path | tùy chọn | string | Vị trí của tệp keypair chương trình |
idl_path | tùy chọn | string | Vị trí của tệp IDL chương trình |
bin_path | tùy chọn | string | Vị trí của tệp nhị phân chương trình |
variable "contract" {value = svm::get_program_from_native_project("my_program")}output "idl" {value = variable.contract.idl}
sol_to_lamports
svm::sol_to_lamports chuyển đổi lượng SOL được cung cấp sang lamport.
output "lamports" {value = svm::sol_to_lamports(1.1)}// lamports: 1100000000
lamports_to_sol
svm::lamports_to_sol chuyển đổi số lượng lamport được cung cấp sang SOL.
output "sol" {value = svm::lamports_to_sol(1100000000)}// sol: 1.1
find_pda
svm::find_pda tìm một PDA hợp lệ bằng cách sử dụng program id và các seed được
cung cấp.
Đầu vào
| Tên | Bắt buộc | Kiểu | Mô tả |
|---|---|---|---|
program_id | bắt buộc | string | Địa chỉ của chương trình mà PDA được dẫn xuất từ đó |
seeds | tùy chọn | array[string] | Một mảng seed tùy chọn (tối đa 16 seed, mỗi seed 32 byte) |
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 tính toán địa chỉ của associated token
account cho địa chỉ ví và địa chỉ token mint được cung cấp.
Đầu vào
| Name | Required | Type | Description |
|---|---|---|---|
wallet_address | required | string | Địa chỉ của ví |
token_mint_address | optional | string | Địa chỉ của token mint |
variable "token_account" {value = svm::get_associated_token_account(signer.caller.address, "So11111111111111111111111111111111111111112")}
create_token_account_instruction
svm::create_token_account_instruction tạo các byte lệnh thô để tạo một
associated token account.
Đầu vào
| Name | Required | Type | Description |
|---|---|---|---|
funding_address | required | string | Địa chỉ của tài khoản cấp vốn |
wallet_address | required | string | Địa chỉ của ví |
token_mint_address | optional | string | Địa chỉ của token mint |
token_program_id | optional | string | Địa chỉ của 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 tạo biểu diễn mảng byte của một số nguyên u64, phù hợp để sử dụng làm
seed trong quá trình dẫn xuất PDA.
Đầu vào
| Name | Required | Type | Description |
|---|---|---|---|
value | required | integer | Số nguyên u64 cần chuyển đổi thành mảng byte |
variable "pda" {value = svm::find_pda("3bv3j4GvMPjvvBX9QdoX27pVoWhDSXpwKZipFF1QiVr6", [svm::u64(1000000000)])}
i64
svm::i64 tạo biểu diễn mảng byte của một số nguyên i64, phù hợp để sử dụng làm
seed trong quá trình dẫn xuất PDA.
Đầu vào
| Name | Required | Type | Description |
|---|---|---|---|
value | required | integer | Số nguyên i64 cần chuyển đổi thành mảng byte |
variable "pda" {value = svm::find_pda("3bv3j4GvMPjvvBX9QdoX27pVoWhDSXpwKZipFF1QiVr6", [svm::i64(-1000000000)])}
Is this page helpful?