はじめに
ファンジブルトークンを転送する
Last updated November 25, 2025
Solanaブロックチェーン上でウォレット間でファンジブルトークン(SPLトークン)を転送します。
トークンを転送する
以下のセクションでは、完全なコード例と変更が必要なパラメータを確認できます。トークン転送の詳細については、Token Metadataプログラムページをご覧ください。
1// To install all the required packages use the following command
2// npm install @metaplex-foundation/mpl-toolbox @metaplex-foundation/umi @metaplex-foundation/umi-bundle-defaults
3import {
4 createTokenIfMissing,
5 findAssociatedTokenPda,
6 transferTokens,
7} from '@metaplex-foundation/mpl-toolbox';
8import {
9 keypairIdentity,
10 publicKey,
11 transactionBuilder,
12} from '@metaplex-foundation/umi';
13import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
14import { readFileSync } from 'fs';
15
16// Initialize Umi with Devnet endpoint
17 const umi = createUmi('https://api.devnet.solana.com')
18
19 // Load your wallet/keypair
20 const wallet = '<your wallet file path>'
21 const secretKey = JSON.parse(readFileSync(wallet, 'utf-8'))
22 const keypair = umi.eddsa.createKeypairFromSecretKey(new Uint8Array(secretKey))
23 umi.use(keypairIdentity(keypair))
24
25 // Your token mint address and destination wallet
26 const mintAddress = publicKey('<your token mint address>')
27 const destinationAddress = publicKey('<destination wallet address>')
28
29// Find the source token account (your account)
30 const sourceTokenAccount = findAssociatedTokenPda(umi, {
31 mint: mintAddress,
32 owner: umi.identity.publicKey,
33 })
34
35 // Find the destination token account
36 const destinationTokenAccount = findAssociatedTokenPda(umi, {
37 mint: mintAddress,
38 owner: destinationAddress,
39 })
40
41 // Create the destination token account if it doesn't exist
42 transactionBuilder()
43 .add(createTokenIfMissing(umi, {
44 mint: mintAddress,
45 owner: destinationAddress,
46 }))
47 // Transfer 100 tokens
48 .add(
49 transferTokens(umi, {
50 source: sourceTokenAccount,
51 destination: destinationTokenAccount,
52 amount: 100,
53 }))
54 .sendAndConfirm(umi)
55
56console.log('Transferred 100 tokens')
57 console.log('From:', sourceTokenAccount)
58 console.log('To:', destinationTokenAccount)
1# Transfer Tokens using the Metaplex CLI
2
3# Usage: mplx toolbox token transfer <MINT_ADDRESS> <AMOUNT> <DESTINATION>
4mplx toolbox token transfer <MINT_ADDRESS> <AMOUNT> <DESTINATION_ADDRESS>
5
6# Example: Transfer 100 tokens (0 decimals)
7mplx toolbox token transfer 7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU 100 9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM
8
9# Example: Transfer 100 tokens (9 decimals)
10# Amount is in smallest units: 100 * 10^9 = 100000000000
11mplx toolbox token transfer 7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU 100000000000 9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM
12
13# Note: If the destination doesn't have a token account, it will be created automatically
パラメータ
転送に合わせて以下のパラメータをカスタマイズしてください:
| パラメータ | 説明 |
|---|---|
mintAddress | トークンミントアドレス |
destinationAddress | 受取人のウォレットアドレス |
amount | 転送するトークン数 |
仕組み
転送プロセスには4つの手順が含まれます:
- 送信元トークンアカウントを見つける -
findAssociatedTokenPdaを使用して自分のトークンアカウントを特定 - 宛先トークンアカウントを見つける - 受取人のトークンアカウントを特定
- 必要に応じて宛先トークンアカウントを作成 -
createTokenIfMissingを使用して受取人がトークンアカウントを持っていることを確認 - トークンを転送 -
transferTokensで転送を実行
トークンアカウント
各ウォレットは、保有するトークンの種類ごとにAssociated Token Account(ATA)を持っています。findAssociatedTokenPda関数は、ウォレットアドレスとトークンミントに基づいてこれらのアカウントのアドレスを導出します。
createTokenIfMissing関数は、トークンアカウントがまだ存在しない場合は自動的に作成し、すでに存在する場合は何もしません。これにより、転送は常に成功します。
