Solanaは、0.001ドル未満の手数料で即座にグローバルなトークン転送を可能にします。国境を越えた送金、給与支払い、または財務業務を構築する場合でも、基本的なステーブルコイン支払いは1秒未満で決済され、コストはわずか数分の1セントです。
仕組み
支払いは、送信者のトークンアカウントから受信者のトークンアカウントにステーブルコインを移動します。受信者がこのトークンを初めて受け取る場合、そのトークンアカウントは同じトランザクションの一部として作成できます。
コア支払いの概念については、Solanaでの支払いの仕組みを参照してください。
@solana-program/token-2022 の token2022Program()
プラグインは、@solana/kit クライアントに
client.token2022 ヘルパーを追加します。その transferToATA
メソッドは、ATA の導出とトランザクションの構築を自動的に処理するため、単一の支払い転送に最適です。
以下の手順はコアフローを示しています。完全な実行可能コードについては、デモを参照してください。
トークンヘルパーを作成する
.use(token2022Program()) を使用して、クライアントに token2022Program()
プラグインを追加します。これにより client.token2022 が公開され、その
instructions は一般的なトークン操作のメソッドを提供します。
Token-2022 プログラムが所有するミントには token2022Program()
を使用し、元の Token Program が所有するミントには @solana-program/token の
tokenProgram() を使用してください。
支払いを送信する
transferToATA()
を使用して、ウォレット間でトークンを転送します。このメソッドは以下を処理します:
- ATA の解決: 送信者と受信者の Associated Token Accounts (ATAs) を自動的に導出します。受信者の ATA が存在しない場合、アカウントを作成するための instructions が同じトランザクションに自動的に追加されます。
- 確認済み金額: ミントの
decimalsとともに、基本単位でamountを渡します。転送はオンチェーンでミントの小数点以下の桁数に対して確認されます(例:ミントの小数点以下が 6 桁の場合、250000 基本単位 → 0.25 トークン)。 - トランザクションの構築:
sendTransaction()がトランザクションを構築、署名、送信し、context.signatureにトランザクション署名を保持する結果に解決されます。
const client = createClient().use(signer(sender)).use(solanaLocalRpc()).use(token2022Program());const result = await client.token2022.instructions.transferToATA({mint: mint.address,authority: sender,recipient: recipient.address,amount: 250_000n,decimals: 6}).sendTransaction();
残高の確認
転送が完了したら、RPC からトークン残高を読み取ります。findAssociatedTokenPda()
で各ウォレットの ATA を導出し、getTokenAccountBalance()
を呼び出してそのアカウントの残高を取得します。
const client = createClient().use(signer(sender)).use(solanaLocalRpc()).use(token2022Program());const result = await client.token2022.instructions.transferToATA({mint: mint.address,authority: sender,recipient: recipient.address,amount: 250_000n,decimals: 6}).sendTransaction();const [senderAta] = await findAssociatedTokenPda({mint: mint.address,owner: sender.address,tokenProgram: TOKEN_2022_PROGRAM_ADDRESS});const [recipientAta] = await findAssociatedTokenPda({mint: mint.address,owner: recipient.address,tokenProgram: TOKEN_2022_PROGRAM_ADDRESS});const senderBalance = await client.rpc.getTokenAccountBalance(senderAta).send();const recipientBalance = await client.rpc.getTokenAccountBalance(recipientAta).send();
デモ
// Generate signers for sender and recipientconst sender = await generateKeyPairSigner();const recipient = await generateKeyPairSigner();console.log("Sender Address:", sender.address);console.log("Recipient Address:", recipient.address);// Demo Setup: Create client, mint account, and fund the sender with initial tokensconst { client, mint } = await demoSetup(sender);console.log("\nMint Address:", mint.address);// =============================================================================// Basic Token Payment Demo// =============================================================================// Transfer tokens from sender to recipient. The source and destination ATAs are// derived automatically, and the recipient's ATA is created if it does not exist.const result = await client.token2022.instructions.transferToATA({mint: mint.address,authority: sender,recipient: recipient.address,amount: 250_000n, // 0.25 tokens (base units for a mint with 6 decimals)decimals: 6}).sendTransaction();console.log("\n=== Token Payment Complete ===");console.log("Transaction Signature:", result.context.signature);// Derive the sender and recipient ATAs to read their balancesconst [senderAta] = await findAssociatedTokenPda({mint: mint.address,owner: sender.address,tokenProgram: TOKEN_2022_PROGRAM_ADDRESS});const [recipientAta] = await findAssociatedTokenPda({mint: mint.address,owner: recipient.address,tokenProgram: TOKEN_2022_PROGRAM_ADDRESS});// Fetch final token account balances via RPCconst senderBalance = await client.rpc.getTokenAccountBalance(senderAta).send();const recipientBalance = await client.rpc.getTokenAccountBalance(recipientAta).send();console.log("\nSender Token Account Balance:",senderBalance.value.uiAmountString);console.log("Recipient Token Account Balance:",recipientBalance.value.uiAmountString);// =============================================================================// Demo Setup Helper Function// =============================================================================
Is this page helpful?