SOL転送

Solanaの最も基本的なトランザクション:あるアカウントから別のアカウントへSOLを移動します。これは、より複雑なプログラムロジックをテストする前に、LiteSVMのセットアップが正しく機能するかを確認するための最初のテストとして最適です。

完全なサンプル

import { createClient, generateKeyPairSigner, lamports } from "@solana/kit";
import { litesvm } from "@solana/kit-plugin-litesvm";
import { signer } from "@solana/kit-plugin-signer";
import { systemProgram } from "@solana-program/system";
// Payer first, then the LiteSVM transport, then program plugins.
const mySigner = await generateKeyPairSigner();
const client = createClient()
.use(signer(mySigner))
.use(litesvm())
.use(systemProgram());
const recipient = await generateKeyPairSigner();
// Airdrop SOL to the payer
client.svm.airdrop(client.payer.address, lamports(10_000_000_000n));
// Check initial balance
const senderInitial = client.svm.getBalance(client.payer.address) ?? 0n;
console.log("Sender initial:", Number(senderInitial) / 1e9, "SOL");
// Build and send the transfer
await client.system.instructions
.transferSol({
source: client.payer,
destination: recipient.address,
amount: lamports(1_000_000_000n) // 1 SOL
})
.sendTransaction();
// Check final balances
const senderFinal = client.svm.getBalance(client.payer.address) ?? 0n;
const recipientFinal = client.svm.getBalance(recipient.address) ?? 0n;
console.log("Sender final:", Number(senderFinal) / 1e9, "SOL");
console.log("Recipient final:", Number(recipientFinal) / 1e9, "SOL");

期待される出力

Sender initial: 10 SOL
Sender final: 8.999995 SOL
Recipient final: 1 SOL

送信者の最終残高は、トランザクション手数料(署名あたり5,000 lamport)により、9 SOLをわずかに下回ります。

これは最もシンプルなトランザクションタイプについての説明です。カスタムプログラムを使ったテストについては、プログラムテストを参照してください。トークン転送(ミント、ATA)については、トークンテストを参照してください。

Is this page helpful?

目次

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