Memo ile ödeme

Solana'nın memo programı, herhangi bir ödemeye fatura numaraları, sipariş kimlikleri veya özel referanslar eklemenize olanak tanır. Bu memolar kalıcı olarak zincir üzerinde kaydedilir ve işlem günlüklerinde görünür, böylece ödemeleri dahili sistemlerinizle eşleştirmeyi kolaylaştırır.

Nasıl çalışır

Memo programı, işlemin günlüklerine metin yazar. Bu günlükler, gezginler ve RPC sağlayıcıları tarafından indekslenir, böylece memolar ödeme mutabakatı için aranabilir hale gelir.

Temel ödeme kavramları için Solana'da ödemeler nasıl çalışır bölümüne bakın.

Memo eklemek, talimatları doğrudan oluşturmayı gerektirir, bu da işleme nelerin dahil edileceği konusunda size kontrol sağlar.

Aşağıdaki adımlar temel akışı gösterir. Tam çalıştırılabilir kod için Demo bölümüne bakın.

Memo programını içe aktar

@solana-program/memo paketinden getAddMemoInstruction fonksiyonunu içe aktararak memo talimatları oluşturun.

Transfer talimatı oluştur

Kaynak ATA, hedef ATA, yetki (imzalayan) ve temel birimlerdeki tutarı belirterek token transfer talimatını oluşturun.

Memo talimatı oluştur

Bir mesaj içeren memo talimatı oluşturun. Bu mesaj, işlemin program günlüklerinde görünür olacaktır.

Memo ile işlem gönder

Transfer ve memo talimatlarını tek bir işlemde birleştirin.

İşlem günlüklerinde notu görüntüle

İşlem onaylandıktan sonra, günlüklerdeki notu görüntülemek için işlemi getirin. Not, Memo programından bir günlük mesajı olarak görünür.

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"

Memo programını içe aktar

@solana-program/memo paketinden getAddMemoInstruction fonksiyonunu içe aktararak memo talimatları oluşturun.

Transfer talimatı oluştur

Kaynak ATA, hedef ATA, yetki (imzalayan) ve temel birimlerdeki tutarı belirterek token transfer talimatını oluşturun.

Memo talimatı oluştur

Bir mesaj içeren memo talimatı oluşturun. Bu mesaj, işlemin program günlüklerinde görünür olacaktır.

Memo ile işlem gönder

Transfer ve memo talimatlarını tek bir işlemde birleştirin.

İşlem günlüklerinde notu görüntüle

İşlem onaylandıktan sonra, günlüklerdeki notu görüntülemek için işlemi getirin. Not, Memo programından bir günlük mesajı olarak görünür.

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?

İçindekiler

Sayfayı Düzenle

Yönetici

© 2026 Solana Vakfı.
Tüm hakları saklıdır.
Bağlanın