메모가 포함된 결제

Solana의 메모 프로그램을 사용하면 모든 결제에 송장 번호, 주문 ID 또는 사용자 지정 참조를 첨부할 수 있습니다. 이러한 메모는 온체인에 영구적으로 기록되고 트랜잭션 로그에 표시되므로 결제를 내부 시스템과 쉽게 매칭할 수 있습니다.

작동 방식

메모 프로그램은 트랜잭션 로그에 텍스트를 기록합니다. 이러한 로그는 익스플로러와 RPC 제공자에 의해 인덱싱되므로 결제 조정을 위해 메모를 검색할 수 있습니다.

핵심 결제 개념은 Solana에서 결제가 작동하는 방식을 참조하세요.

메모를 추가하려면 인스트럭션을 직접 빌드해야 하며, 이를 통해 트랜잭션에 포함되는 내용을 제어할 수 있습니다.

아래 단계는 핵심 흐름을 보여줍니다. 완전히 실행 가능한 코드는 데모를 참조하세요.

메모 프로그램 가져오기

@solana-program/memo에서 getAddMemoInstruction를 가져와 메모 인스트럭션을 생성합니다.

전송 인스트럭션 생성

소스 ATA, 대상 ATA, 권한(서명자) 및 기본 단위의 금액을 지정하여 토큰 전송 인스트럭션을 생성합니다.

메모 인스트럭션 생성

메시지와 함께 메모 인스트럭션을 생성합니다. 이 메시지는 트랜잭션의 프로그램 로그에 표시됩니다.

메모와 함께 트랜잭션 전송

전송 및 메모 인스트럭션을 단일 트랜잭션으로 결합합니다.

거래 로그에서 메모 보기

거래가 확인된 후, 거래를 가져와서 로그에서 메모를 확인하세요. 메모는 메모 프로그램의 로그 메시지로 나타납니다.

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"

메모 프로그램 가져오기

@solana-program/memo에서 getAddMemoInstruction를 가져와 메모 인스트럭션을 생성합니다.

전송 인스트럭션 생성

소스 ATA, 대상 ATA, 권한(서명자) 및 기본 단위의 금액을 지정하여 토큰 전송 인스트럭션을 생성합니다.

메모 인스트럭션 생성

메시지와 함께 메모 인스트럭션을 생성합니다. 이 메시지는 트랜잭션의 프로그램 로그에 표시됩니다.

메모와 함께 트랜잭션 전송

전송 및 메모 인스트럭션을 단일 트랜잭션으로 결합합니다.

거래 로그에서 메모 보기

거래가 확인된 후, 거래를 가져와서 로그에서 메모를 확인하세요. 메모는 메모 프로그램의 로그 메시지로 나타납니다.

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
// 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 솔라나 재단.
모든 권리 보유.
연결하기