SolanaドキュメントLiteSVMTypeScriptAPIリファレンス

トランザクション

トランザクションの送信、シミュレート、および管理のためのメソッド。

sendTransaction

sendTransaction(tx: Transaction): TransactionMetadata | FailedTransactionMetadata

トランザクションを実行します。成功時はメタデータを返し、エラー時は失敗の詳細を返します。

const result = client.svm.sendTransaction(signedTx);
// Check for errors
if ("err" in result && result.err()) {
console.error("Transaction failed:", result.err());
return;
}
// Access result properties (note: these are getter functions)
console.log("Signature:", result.signature());
console.log("Compute units:", result.computeUnitsConsumed());
console.log("Logs:", result.logs());

トランザクション結果のプロパティ(err()computeUnitsConsumed()logs()signature())はゲッター関数であり、プロパティではありません。常に 括弧を付けて呼び出してください。

TransactionMetadata のメソッド

メソッド戻り値説明
signature()Uint8Arrayトランザクション署名のバイト列
computeUnitsConsumed()bigint使用されたコンピュートユニット数
logs()string[]プログラムログ
innerInstructions()InnerInstruction[]内部(CPI)instructions
returnData()TransactionReturnDataプログラムからの戻りデータ
prettyLogs()stringカラー付きのフォーマット済みログ

simulateTransaction

simulateTransaction(tx: Transaction): SimulatedTransactionInfo | FailedTransactionMetadata

状態を変更せずにトランザクションをシミュレートします。

const simResult = client.svm.simulateTransaction(signedTx);
if ("err" in simResult && simResult.err()) {
console.error("Simulation failed:", simResult.err());
return;
}
// Use .meta() to get TransactionMetadata
const meta = simResult.meta();
console.log("Would use", meta.computeUnitsConsumed(), "compute units");
console.log("Logs:", meta.logs());
// Get post-execution account states
const postAccounts = simResult.postAccounts();
console.log("Post-state accounts:", postAccounts);

シミュレーションは状態を変更しません。送信前にトランザクションを確認するために使用してください。

ブロックハッシュの管理

latestBlockhash

latestBlockhash(): Blockhash

現在のブロックハッシュを取得します。

const blockhash = client.svm.latestBlockhash();
console.log("Blockhash:", blockhash);

getLatestBlockhash(client.rpc 経由)

トランザクションを手動で構築するために、有効期限情報付きのブロックハッシュを取得します。 blockhashlastValidBlockHeight の両方を返すため、RPCヘルパーを使用してください。

import {
createTransactionMessage,
setTransactionMessageLifetimeUsingBlockhash
} from "@solana/kit";
const { value: blockhashLifetime } = await client.rpc
.getLatestBlockhash()
.send();
const tx = setTransactionMessageLifetimeUsingBlockhash(
blockhashLifetime,
createTransactionMessage({ version: 0 })
);

systemProgram()tokenProgram() などのプログラムプラグインを使用する場合、 ブロックハッシュを自分で取得する必要はありません。client.sendTransaction()(および instructionチェーン上の .sendTransaction() ヘルパー)が自動的に処理します。

expireBlockhash

expireBlockhash(): LiteSVM

新しいブロックハッシュに進めます。ブロックハッシュの有効期限切れシナリオのテストに便利です。

const oldBlockhash = client.svm.latestBlockhash();
client.svm.expireBlockhash();
const newBlockhash = client.svm.latestBlockhash();
console.log("Old:", oldBlockhash);
console.log("New:", newBlockhash);
// Blockhashes will be different

トランザクション履歴

送信後にトランザクションを取得するには、トランザクション履歴を有効にしてください:

// Enable history storage (stores last N transactions)
client.svm.withTransactionHistory(100n);
// Send a transaction
const result = client.svm.sendTransaction(signedTx);
// Later, retrieve it by signature (base58 string)
// Note: getTransaction expects a base58-encoded signature string

Is this page helpful?

目次

ページを編集
© 2026 Solana Foundation. 無断転載を禁じます。