SolanaドキュメントInfrastructure as CodeSVM アドオン

SVM関数

これらの関数は、SolanaおよびSVM互換ブロックチェーン向けのSVMアドオンを使用する際に利用できます。

system_program_id

svm::system_program_id はSystem Programのidを返します。 11111111111111111111111111111111

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

default_pubkey

svm::default_pubkey はデフォルトのpubkeyを返します。 11111111111111111111111111111111

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

get_instruction_data_from_idl_path

svm::get_instruction_data_from_idl_path は、プログラム呼び出し用のエンコードされたinstruction dataを作成し、指定されたIDLファイルに基づいて型チェックとシリアライゼーションを提供します。

入力

NameRequiredTypeDescription
idl_pathrequiredstringtxtx.yml からの相対パス(IDL .json ファイルへのパス)
instruction_namerequiredstringデータを生成するinstructionsの名前
argumentsoptionalarray[string]データを生成するinstructionsの引数
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 は、プログラム呼び出し用のエンコードされたinstruction dataを作成し、指定されたIDLデータに基づいて型チェックとシリアライゼーションを提供します。

入力

NameRequiredTypeDescription
idlrequiredstring | SVM_IDLプログラムIDL
instruction_namerequiredstringIDLによってインデックスされた、データを生成するinstructionsの名前
argumentsoptionalarray[string]データを生成するinstructionsの引数
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 は、AnchorプロジェクトのプログラムのデプロイメントアーティファクトをAnchorプロジェクトから取得します。

入力

名前必須説明
program_name必須stringデプロイされるプログラムの名前
keypair_path任意stringプログラムのkeypairファイルの場所
idl_path任意stringプログラムのIDLファイルの場所
bin_path任意stringプログラムのバイナリファイルの場所
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 は、非Anchorプログラムのデプロイメントアーティファクトを取得します。

入力

名前必須説明
program_name必須stringデプロイされるプログラムの名前
keypair_path任意stringプログラムのkeypairファイルの場所
idl_path任意stringプログラムのIDLファイルの場所
bin_path任意stringプログラムのバイナリファイルの場所
variable "contract" {
value = svm::get_program_from_native_project("my_program")
}
output "idl" {
value = variable.contract.idl
}

sol_to_lamports

svm::sol_to_lamports は、指定されたSOL量をlamportに変換します。

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

lamports_to_sol

svm::lamports_to_sol は、指定されたlamport数をSOLに変換します。

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

find_pda

svm::find_pda は、指定されたプログラムIDとシードを使用して有効なPDAを検索します。

入力

名前必須説明
program_id必須stringPDAの導出元となるプログラムのアドレス
seeds任意array[string]シードのオプション配列(最大16個、各32バイト)
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 は、指定されたウォレットおよびトークンミントアドレスに対応する associated token account のアドレスを計算します。

入力

名前必須説明
wallet_address必須stringウォレットのアドレス
token_mint_address任意stringトークンミントのアドレス
variable "token_account" {
value = svm::get_associated_token_account(signer.caller.address, "So11111111111111111111111111111111111111112")
}

create_token_account_instruction

svm::create_token_account_instruction は、associated token account を作成するための生のinstructions バイトを生成します。

入力

名前必須説明
funding_address必須string資金提供アカウントのアドレス
wallet_address必須stringウォレットのアドレス
token_mint_address任意stringトークンミントのアドレス
token_program_id任意stringToken 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 は、u64 整数のバイト配列表現を生成します。PDA 導出における seed としての使用に適しています。

入力

名前必須説明
value必須integerバイト配列に変換する u64 整数
variable "pda" {
value = svm::find_pda("3bv3j4GvMPjvvBX9QdoX27pVoWhDSXpwKZipFF1QiVr6", [svm::u64(1000000000)])
}

i64

svm::i64 は、i64 整数のバイト配列表現を生成します。PDA 導出における seed としての使用に適しています。

入力

名前必須説明
value必須integerバイト配列に変換する i64 整数
variable "pda" {
value = svm::find_pda("3bv3j4GvMPjvvBX9QdoX27pVoWhDSXpwKZipFF1QiVr6", [svm::i64(-1000000000)])
}

Is this page helpful?

© 2026 Solana Foundation. 無断転載を禁じます。