Payment with Memo

Solana's memo program lets you attach invoice numbers, order IDs, or custom references to any payment. These memos are permanently recorded on-chain and visible in transaction logs, making it easy to match payments to your internal systems.

How It Works

The Memo program writes text to the transaction's logs. These logs are indexed by explorers and RPC providers, making memos searchable for payment reconciliation.

See How Payments Work on Solana for core payment concepts.

Adding a memo requires building instructions directly, which gives you control over what's included in the transaction.

The steps below show the core flow. See the Demo for complete runnable code.

Import Memo Program

Import getAddMemoInstruction from @solana-program/memo to create memo instructions.

Payment with Memo
import { getAddMemoInstruction } from "@solana-program/memo";

Create Transfer Instruction

Create the token transfer instruction specifying the source ATA, destination ATA, authority (signer), and amount in base units.

Payment with Memo
import { getAddMemoInstruction } from "@solana-program/memo";
const transferInstruction = getTransferInstruction({
source: senderAta,
destination: recipientAta,
authority: sender.address,
amount: 250_000n // adjusted for the mint's decimals
});

Create Memo Instruction

Create a memo instruction with a message. This message will be visible in the program logs of the transaction.

Payment with Memo
import { getAddMemoInstruction } from "@solana-program/memo";
const transferInstruction = getTransferInstruction({
source: senderAta,
destination: recipientAta,
authority: sender.address,
amount: 250_000n
});
const memoInstruction = getAddMemoInstruction({
memo: "Payment for services rendered - Invoice #12345"
});

Send Transaction with Memo

Combine the transfer and memo instructions in a single transaction.

Payment with Memo
import { getAddMemoInstruction } from "@solana-program/memo";
const transferInstruction = getTransferInstruction({
source: senderAta,
destination: recipientAta,
authority: sender.address,
amount: 250_000n
});
const memoInstruction = getAddMemoInstruction({
memo: "Payment for services rendered - Invoice #12345"
});
const signature = await client.transaction.prepareAndSend({
authority: sender,
instructions: [transferInstruction, memoInstruction],
version: 0
});

View Memo in Transaction Logs

After the transaction confirms, fetch it to view the memo in the logs. The memo appears as a log message from the Memo program.

Payment with Memo
import { getAddMemoInstruction } from "@solana-program/memo";
const transferInstruction = getTransferInstruction({
source: senderAta,
destination: recipientAta,
authority: sender.address,
amount: 250_000n
});
const memoInstruction = getAddMemoInstruction({
memo: "Payment for services rendered - Invoice #12345"
});
const signature = await client.transaction.prepareAndSend({
authority: sender,
instructions: [transferInstruction, memoInstruction],
version: 0
});
const transaction = await client.runtime.rpc
.getTransaction(signature, {
encoding: "jsonParsed",
maxSupportedTransactionVersion: 0
})
.send();
console.log("Transaction logs with Memo:");
console.log(transaction?.meta?.logMessages);
Example Transaction Logs
"Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [1]",
"Program log: Instruction: Transfer",
"Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb consumed 1682 of 200000 compute units",
"Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb success",
"Program MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr invoke [1]",
'Program log: Memo (len 46): "Payment for services rendered - Invoice #12345"',
"Program MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr consumed 18097 of 198318 compute units",
"Program MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr success",
"Program ComputeBudget111111111111111111111111111111 invoke [1]",
"Program ComputeBudget111111111111111111111111111111 success"

Import Memo Program

Import getAddMemoInstruction from @solana-program/memo to create memo instructions.

Create Transfer Instruction

Create the token transfer instruction specifying the source ATA, destination ATA, authority (signer), and amount in base units.

Create Memo Instruction

Create a memo instruction with a message. This message will be visible in the program logs of the transaction.

Send Transaction with Memo

Combine the transfer and memo instructions in a single transaction.

View Memo in Transaction Logs

After the transaction confirms, fetch it to view the memo in the logs. The memo appears as a log message from the Memo program.

Example Transaction Logs
"Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [1]",
"Program log: Instruction: Transfer",
"Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb consumed 1682 of 200000 compute units",
"Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb success",
"Program MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr invoke [1]",
'Program log: Memo (len 46): "Payment for services rendered - Invoice #12345"',
"Program MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr consumed 18097 of 198318 compute units",
"Program MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr success",
"Program ComputeBudget111111111111111111111111111111 invoke [1]",
"Program ComputeBudget111111111111111111111111111111 success"
Payment with Memo
import { getAddMemoInstruction } from "@solana-program/memo";

Demo

Demo
// Generate keypairs for sender and recipient
const sender = (await generateKeypair()).signer;
const recipient = (await generateKeypair()).signer;
console.log("Sender Address:", sender.address);
console.log("Recipient Address:", recipient.address);
// Demo Setup: Create client, mint account, token accounts, and fund with initial tokens
const { client, mint } = await demoSetup(sender, recipient);
console.log("\nMint Address:", mint.address);
// Derive the Associated Token Accounts addresses (ATAs) for sender and recipient
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
});
console.log("Sender Token Account:", senderAta.toString());
console.log("Recipient Token Account:", recipientAta.toString());
// =============================================================================
// Token Payment with Memo Demo
// =============================================================================
// Create instruction to transfer tokens from sender to recipient
// Transferring 250,000 base units = 0.25 tokens (with 6 decimals)
const transferInstruction = getTransferInstruction({
source: senderAta,
destination: recipientAta,
authority: sender.address,
amount: 250_000n // 0.25 tokens
});
// Create instruction to add a memo to the transaction
const memoInstruction = getAddMemoInstruction({
memo: "Payment for services rendered - Invoice #12345"
});
// Prepare and send transaction with both transfer and memo using @solana/client
const signature = await client.transaction.prepareAndSend({
authority: sender,
instructions: [transferInstruction, memoInstruction],
version: 0
});
console.log("\n=== Token Payment with Memo Complete ===");
console.log("Transaction Signature:", signature.toString());
// Fetch final token account balances using @solana/client SPL token helper
const splToken = client.splToken({
mint: mint.address,
tokenProgram: "auto"
});
const senderBalance = await splToken.fetchBalance(sender.address);
const recipientBalance = await splToken.fetchBalance(recipient.address);
console.log("\nSender Token Account Balance:", senderBalance);
console.log("Recipient Token Account Balance:", recipientBalance);
// Fetch transaction details to view the memo in the logs
const transaction = await client.runtime.rpc
.getTransaction(signature, {
encoding: "jsonParsed",
maxSupportedTransactionVersion: 0
})
.send();
console.log("\nTransaction logs with Memo:");
console.log(transaction?.meta?.logMessages);
// =============================================================================
// Demo Setup Helper Function
// =============================================================================
Console
Click to execute the code.

Is this page helpful?

सामग्री तालिका

पृष्ठ संपादित करें

द्वारा प्रबंधित

© 2026 सोलाना फाउंडेशन। सर्वाधिकार सुरक्षित।
जुड़े रहें