기본 결제

Solana는 $0.001 미만의 수수료로 즉각적인 글로벌 토큰 전송을 가능하게 합니다. 국경 간 송금, 급여 지급 또는 자금 관리 운영을 구축하든, 기본 스테이블코인 결제는 1초 이내에 정산되며 비용은 1센트의 일부에 불과합니다.

작동 방식

결제는 발신자의 token account에서 수신자의 token account로 스테이블코인을 이동시킵니다. 수신자가 이 토큰을 처음 받는 경우, 해당 token account는 동일한 트랜잭션의 일부로 생성될 수 있습니다.

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

@solana/clientsplToken 헬퍼는 ATA 유도, 소수점 변환 및 트랜잭션 구축을 자동으로 처리합니다. 이는 단일 결제 전송에 이상적입니다.

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

토큰 헬퍼 생성

mint 주소로 client.splToken()를 호출하여 splToken() 헬퍼를 구성합니다. 헬퍼는 일반적인 토큰 작업을 위한 메서드를 제공합니다.

tokenProgram: "auto"를 설정하면 mint account가 Token 프로그램 또는 Token-2022 프로그램 소유인지 자동으로 감지합니다.

결제 전송

sendTransfer()를 사용하여 지갑 간 토큰을 전송합니다. 이 메서드는 다음을 처리합니다:

  • ATA 해결: 발신자와 수신자의 연관 토큰 계정(ATA)을 자동으로 유도합니다. 수신자의 ATA가 존재하지 않는 경우, 계정을 생성하는 명령이 동일한 트랜잭션에 자동으로 추가됩니다.
  • 소수점 변환: 토큰 금액을 받아들이고 mint의 소수점 자릿수를 기반으로 기본 단위로 자동 변환합니다(예: mint가 6자리 소수점을 가진 경우 0.25 토큰 -> 250000 기본 단위)
  • 트랜잭션 구축: 전송 명령으로 트랜잭션을 생성, 서명 및 전송합니다
Basic Payment
const client = createClient({
endpoint: "http://localhost:8899",
websocketEndpoint: "ws://localhost:8900",
commitment: "confirmed"
});
const splToken = client.splToken({
mint: mint.address,
tokenProgram: "auto"
});
const signature = await splToken.sendTransfer({
amount: 0.25,
authority: sender,
destinationOwner: recipient.address
});

잔액 확인

전송이 완료된 후 fetchBalance()를 사용하여 토큰 잔액을 확인합니다. 이 메서드는 지갑 주소를 받아 자동으로 해당 ATA를 도출하여 잔액을 가져옵니다.

Basic Payment
const client = createClient({
endpoint: "http://localhost:8899",
websocketEndpoint: "ws://localhost:8900",
commitment: "confirmed"
});
const splToken = client.splToken({
mint: mint.address,
tokenProgram: "auto"
});
const signature = await splToken.sendTransfer({
amount: 0.25,
authority: sender,
destinationOwner: recipient.address
});
const senderBalance = await splToken.fetchBalance(sender.address);
const recipientBalance = await splToken.fetchBalance(recipient.address);

토큰 헬퍼 생성

mint 주소로 client.splToken()를 호출하여 splToken() 헬퍼를 구성합니다. 헬퍼는 일반적인 토큰 작업을 위한 메서드를 제공합니다.

tokenProgram: "auto"를 설정하면 mint account가 Token 프로그램 또는 Token-2022 프로그램 소유인지 자동으로 감지합니다.

결제 전송

sendTransfer()를 사용하여 지갑 간 토큰을 전송합니다. 이 메서드는 다음을 처리합니다:

  • ATA 해결: 발신자와 수신자의 연관 토큰 계정(ATA)을 자동으로 유도합니다. 수신자의 ATA가 존재하지 않는 경우, 계정을 생성하는 명령이 동일한 트랜잭션에 자동으로 추가됩니다.
  • 소수점 변환: 토큰 금액을 받아들이고 mint의 소수점 자릿수를 기반으로 기본 단위로 자동 변환합니다(예: mint가 6자리 소수점을 가진 경우 0.25 토큰 -> 250000 기본 단위)
  • 트랜잭션 구축: 전송 명령으로 트랜잭션을 생성, 서명 및 전송합니다

잔액 확인

전송이 완료된 후 fetchBalance()를 사용하여 토큰 잔액을 확인합니다. 이 메서드는 지갑 주소를 받아 자동으로 해당 ATA를 도출하여 잔액을 가져옵니다.

Basic Payment
const client = createClient({
endpoint: "http://localhost:8899",
websocketEndpoint: "ws://localhost:8900",
commitment: "confirmed"
});
const splToken = client.splToken({
mint: mint.address,
tokenProgram: "auto"
});

데모

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);
// =============================================================================
// Basic Token Payment Demo
// =============================================================================
// Create splToken helper for this mint using @solana/client
const splToken = client.splToken({
mint: mint.address,
tokenProgram: "auto"
});
// Transfer tokens from sender to recipient (ATA and decimals handled automatically)
const signature = await splToken.sendTransfer({
amount: 0.25,
authority: sender,
destinationOwner: recipient.address
});
console.log("\n=== Token Payment Complete ===");
console.log("Transaction Signature:", signature.toString());
// Fetch final token account balances using splToken helper
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);
// =============================================================================
// Demo Setup Helper Function
// =============================================================================
Console
Click to execute the code.

Is this page helpful?

목차

페이지 편집

관리자

© 2026 솔라나 재단.
모든 권리 보유.
연결하기