Tài liệu SolanaCơ sở hạ tầng dưới dạng mãSVM Addon

Hàm SVM

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

NameRequiredTypeDescription
idl_pathrequiredstringĐường dẫn, tương đối với txtx.yml, đến tệp IDL .json
instruction_namerequiredstringTên của lệnh cần tạo dữ liệu
argumentsoptionalarray[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

NameRequiredTypeDescription
idlrequiredstring | SVM_IDLIDL của chương trình
instruction_namerequiredstringTên của lệnh cần tạo dữ liệu, theo chỉ mục trong IDL
argumentsoptionalarray[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ênBắt buộcKiểuMô tả
program_namebắt buộcstringTên của chương trình đang được triển khai
keypair_pathtùy chọnstringVị trí của tệp keypair chương trình
idl_pathtùy chọnstringVị trí của tệp IDL chương trình
bin_pathtùy chọnstringVị 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ênBắt buộcKiểuMô tả
program_namebắt buộcstringTên của chương trình đang được triển khai
keypair_pathtùy chọnstringVị trí của tệp keypair chương trình
idl_pathtùy chọnstringVị trí của tệp IDL chương trình
bin_pathtùy chọnstringVị 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ênBắt buộcKiểuMô tả
program_idbắt buộcstringĐịa chỉ của chương trình mà PDA được dẫn xuất từ đó
seedstùy chọnarray[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

NameRequiredTypeDescription
wallet_addressrequiredstringĐịa chỉ của ví
token_mint_addressoptionalstringĐị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

NameRequiredTypeDescription
funding_addressrequiredstringĐịa chỉ của tài khoản cấp vốn
wallet_addressrequiredstringĐịa chỉ của ví
token_mint_addressoptionalstringĐịa chỉ của token mint
token_program_idoptionalstringĐị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 address
signer.caller.address, // wallet address
variable.token_mint, // token mint address
variable.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

NameRequiredTypeDescription
valuerequiredintegerSố 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

NameRequiredTypeDescription
valuerequiredintegerSố 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?