ÖdemelerGelişmiş ödemeler

Harcama izinleri

Solana'nın Token Programları delegasyonu destekler—başka bir hesaba, token hesabınızdan belirli bir limite kadar token transfer etme izni vermek. Bu, fonlarınızın kontrolünden vazgeçmeden otomatik ödemeler, emanet hizmetleri ve üçüncü taraf ödeme işleme gibi kullanım senaryolarını mümkün kılar.

Delegasyon nasıl çalışır

Bir delegeyi onayladığınızda, belirli bir hesaba sizin adınıza token transfer etme yetkisi veriyorsunuz:

  • Sahip kontrolü elinde tutar: Tokenlar hala size aittir ve istediğiniz zaman transfer edebilir veya iptal edebilirsiniz
  • Sınırlı harcama: Delege yalnızca onaylanan miktara kadar transfer yapabilir
  • Hesap başına tek delege: Her token hesabının yalnızca bir aktif delegesi olabilir
  • Yeni onay eskisinin yerini alır: Yeni bir delegeyi onaylamak, öncekini otomatik olarak iptal eder

Delegasyon emanetsizdir. Delege, limite kadar token harcayabilir, ancak onaylanan miktarın ötesinde hesaba erişemez veya hesabı boşaltamaz. Sahip istediği zaman iptal edebilir.

İş kullanım senaryoları

Kullanım senaryosuDelegasyon nasıl yardımcı olur
Ödeme işlemcileriSatıcı, işlemciye işlemleri sonuçlandırma izni verir
Otomatik bordroHazine, bordro hizmetine maaşları dağıtma yetkisi verir
Emanet hizmetleriAlıcı, koşullu serbest bırakma için emanet acentesine delege eder
Ticaret platformlarıKullanıcı, borsaya kendi adına işlem yapma yetkisi verir
Kart ihracıKullanıcı, kart düzenleyicisine token hesabından alışveriş yapma yetkisi verir

Bir delegeyi onaylama

Başka bir hesaba, hesabınızdan token harcama izni verin:

import { getApproveCheckedInstruction } from "@solana-program/token";
// Approve delegate to spend up to 1,000 USDC (6 decimals)
const approveInstruction = getApproveCheckedInstruction({
source: tokenAccountAddress, // Your token account
mint: usdcMintAddress, // USDC mint
delegate: delegateAddress, // Account receiving permission
owner: ownerKeypair, // You (must sign)
amount: 1_000_000_000n, // 1,000 USDC in base units
decimals: 6
});

Parametreler:

  • source: İzin veren token hesabı
  • delegate: Harcama iznine sahip olacak hesap
  • owner: Token hesabının mevcut sahibi (işlemi imzalamalıdır)
  • amount: Temsilcinin transfer edebileceği maksimum token miktarı
  • decimals: Doğrulama için token ondalık basamak sayısı (ondalık hataları önler)

Demo

Approve Delegate
// Generate keypairs for sender and delegate
const sender = (await generateKeypair()).signer;
const delegate = (await generateKeypair()).signer;
console.log("Sender Address:", sender.address);
console.log("Delegate Address:", delegate.address);
// Demo Setup: Create client, mint account, token account, and fund with initial tokens
const { client, mint, senderAta } = await demoSetup(sender);
console.log("\nMint Address:", mint.address);
console.log("Sender ATA:", senderAta);
// =============================================================================
// Approve Delegate
// =============================================================================
// Create instruction to approve delegate
const approveInstruction = getApproveCheckedInstruction({
source: senderAta,
mint: mint.address,
delegate: delegate.address,
owner: sender,
amount: 1_000_000n, // 1.0 tokens with 6 decimals
decimals: 6
});
// Send approve transaction
const signature = await client.transaction.prepareAndSend({
authority: sender,
instructions: [approveInstruction]
});
console.log("\n=== Approve Delegate ===");
console.log("Transaction Signature:", signature);
// Fetch token account data to show delegate is set
const tokenData = await fetchToken(client.runtime.rpc, senderAta);
console.log("\nSender Token Account Data:", tokenData.data);
// =============================================================================
// Demo Setup Helper Function
// =============================================================================
Console
Click to execute the code.

Temsilciyi iptal etme

Mevcut temsilciden tüm harcama izinlerini kaldırın:

import { getRevokeInstruction } from "@solana-program/token";
const revokeInstruction = getRevokeInstruction({
source: tokenAccountAddress, // Your token account
owner: ownerKeypair // You (must sign)
});

İptal işlemi tüm temsilci izinlerini kaldırır—kısmi iptal yoktur. Limiti azaltmanız gerekiyorsa, aynı temsilciyi daha düşük bir miktarla onaylayın.

Demo

Revoke Delegate
// Generate keypairs for sender and delegate
const sender = (await generateKeypair()).signer;
const delegate = (await generateKeypair()).signer;
console.log("Sender Address:", sender.address);
console.log("Delegate Address:", delegate.address);
// Demo Setup: Create client, mint account, token account, and fund with initial tokens
const { client, mint, senderAta } = await demoSetup(sender);
console.log("\nMint Address:", mint.address);
console.log("Sender ATA:", senderAta);
// =============================================================================
// Transaction 1: Approve Delegate
// =============================================================================
// Create instruction to approve delegate
const approveInstruction = getApproveCheckedInstruction({
source: senderAta,
mint: mint.address,
delegate: delegate.address,
owner: sender,
amount: 1_000_000n, // 1.0 tokens with 6 decimals
decimals: 6
});
// Send approve transaction
const approveSignature = await client.transaction.prepareAndSend({
authority: sender,
instructions: [approveInstruction]
});
console.log("\n=== Transaction 1: Approve Delegate ===");
console.log("Transaction Signature:", approveSignature);
// Fetch token account data to show delegate is set
const tokenDataAfterApprove = await fetchToken(client.runtime.rpc, senderAta);
console.log("\nSender Token Account Data:", tokenDataAfterApprove.data);
// =============================================================================
// Transaction 2: Revoke Delegate
// =============================================================================
// Create instruction to revoke delegate
const revokeInstruction = getRevokeInstruction({
source: senderAta,
owner: sender
});
// Send revoke transaction
const revokeSignature = await client.transaction.prepareAndSend({
authority: sender,
instructions: [revokeInstruction]
});
console.log("\n=== Transaction 2: Revoke Delegate ===");
console.log("Transaction Signature:", revokeSignature);
// Fetch token account data to show delegate is revoked
const tokenDataAfterRevoke = await fetchToken(client.runtime.rpc, senderAta);
console.log("\nSender Token Account Data:", tokenDataAfterRevoke.data);
// =============================================================================
// Demo Setup Helper Function
// =============================================================================
Console
Click to execute the code.

Temsilci olarak transfer yapma

Temsilci olarak hareket ederken, standart bir transfer kullanın ancak sahip yerine temsilci keypair ile imzalayın:

Transfer as Delegate
import { getTransferCheckedInstruction } from "@solana-program/token";
const transferInstruction = getTransferCheckedInstruction({
source: ownerTokenAccount, // The account you have permission to spend from
mint: usdcMintAddress,
destination: recipientTokenAccount,
authority: delegateKeypair, // You (the delegate) sign, not the owner
amount: 100_000_000n, // 100 USDC
decimals: 6
});

Transfer şu durumlarda başarılı olur:

  • Kaynak hesapta yeterli bakiye varsa
  • Temsilci işlemi imzalarsa

Her transfer kalan ödeneği azaltır. Ödenek sıfıra ulaştığında, temsilci artık token transfer edemez.

Demo

Transfer as Delegate
// Generate keypairs for sender, delegate, and recipient
const sender = (await generateKeypair()).signer;
const delegate = (await generateKeypair()).signer;
const recipient = (await generateKeypair()).signer;
console.log("Sender Address:", sender.address);
console.log("Delegate Address:", delegate.address);
console.log("Recipient Address:", recipient.address);
// Demo Setup: Create client, mint account, token accounts, and fund with initial tokens
const { client, mint, senderAta, recipientAta } = await demoSetup(
sender,
delegate,
recipient
);
console.log("\nMint Address:", mint.address);
console.log("Sender ATA:", senderAta);
console.log("Recipient ATA:", recipientAta);
// =============================================================================
// Transaction 1: Approve Delegate
// =============================================================================
// Create instruction to approve delegate
const approveInstruction = getApproveCheckedInstruction({
source: senderAta,
mint: mint.address,
delegate: delegate.address,
owner: sender,
amount: 1_000_000n, // 1.0 tokens with 6 decimals
decimals: 6
});
// Send approve transaction
const approveSignature = await client.transaction.prepareAndSend({
authority: sender,
instructions: [approveInstruction]
});
console.log("\n=== Transaction 1: Approve Delegate ===");
console.log("Delegate Address:", delegate.address);
console.log("Transaction Signature:", approveSignature);
// =============================================================================
// Fetch Token Account Data to Demonstrate Delegate is Set
// =============================================================================
const tokenAccountData = await fetchToken(client.runtime.rpc, senderAta);
console.log("\nSender Token Account Data:", tokenAccountData.data);
// =============================================================================
// Transaction 2: Transfer Using Delegate
// =============================================================================
// Create instruction to transfer tokens using delegate
// Note: delegate is the authority here, not the owner
const transferInstruction = getTransferCheckedInstruction({
source: senderAta,
mint: mint.address,
destination: recipientAta,
authority: delegate, // Delegate signs this transaction
amount: 500_000n, // 0.5 tokens with 6 decimals
decimals: 6
});
// Send transfer transaction
// Delegate pays for the transaction and authorizes the transfer (sender not needed)
const transferSignature = await client.transaction.prepareAndSend({
authority: delegate, // Delegate pays fee and signs
instructions: [transferInstruction]
});
// =============================================================================
// Fetch Final Token Account Balances
// =============================================================================
const finalSenderToken = await fetchToken(client.runtime.rpc, senderAta);
const finalRecipientToken = await fetchToken(client.runtime.rpc, recipientAta);
console.log("\n=== Transaction 2: Transfer Using Delegate ===");
console.log("Transaction Signature:", transferSignature);
console.log("\nSender Token Account Data:", finalSenderToken.data);
console.log("\nRecipient Token Account Data:", finalRecipientToken.data);
// =============================================================================
// Demo Setup Helper Function
// =============================================================================
Console
Click to execute the code.

Temsilci durumunu kontrol etme

Bir token hesabını sorgulayarak mevcut temsilcisini ve kalan limitini görün:

import { fetchToken } from "@solana-program/token";
const tokenAccount = await fetchToken(rpc, tokenAccountAddress);
if (tokenAccount.data.delegate) {
console.log("Delegate:", tokenAccount.data.delegate);
console.log("Remaining allowance:", tokenAccount.data.delegatedAmount);
} else {
console.log("No delegate set");
}

Demo

Check Delegation Status
// Demo Setup: Create client, mint, two token accounts (one with delegate, one without)
const { client, ataWithDelegate, ataWithoutDelegate } = await demoSetup();
// =============================================================================
// Fetch Token Accounts
// =============================================================================
// Fetch token account with delegate
const tokenWithDelegate = await fetchToken(client.runtime.rpc, ataWithDelegate);
console.log("Token Account with Delegate:", tokenWithDelegate);
// Fetch token account without delegate
const tokenWithoutDelegate = await fetchToken(
client.runtime.rpc,
ataWithoutDelegate
);
console.log("\nToken Account without Delegate:", tokenWithoutDelegate);
// =============================================================================
// Demo Setup Helper Function
// =============================================================================
Console
Click to execute the code.

Güvenlik hususları

Hesap sahipleri için:

  • Yalnızca güvenilir temsilcileri onaylayın
  • Gerekli minimum harcama limitini belirleyin
  • Artık ihtiyaç duyulmadığında temsilci yetkilerini iptal edin
  • Beklenmeyen transferler için hesaplarınızı izleyin

Hizmet sağlayıcılar (temsilciler) için:

  • Talep edilen harcama limitini kullanıcılara açıkça iletin
  • Temsilci hesabınız için uygun anahtar yönetimi uygulayın
  • Limitler tükenmeden önce yeniden onay talep etmek için ödenek tüketimini takip edin

Temsilci yetkisi ile saklama karşılaştırması

ÖzellikTemsilci yetkisiTam saklama
Token sahipliğiKullanıcıda kalırKullanıcı saklayıcıya transfer eder
Harcama kontrolüOnaylanan tutarla sınırlıTransfer edilen fonlara tam erişim
İptalAnında, sahip tarafındanSaklayıcının işbirliği gerektirir
Risk maruziyetiOnaylanan tutarla sınırlıTüm bakiye
Gereken güvenSınırlıYüksek

Temsilci yetkisi bir orta yol sağlar—otomatik ödemeleri mümkün kılarken risk maruziyetini onaylanan tutarla sınırlar.

İlgili kaynaklar

KaynakAçıklama
Temsilci onaylamaBaşka bir hesaba token hesabınızdan harcama izni verme.
Temsilci yetkisini iptal etmeMevcut bir temsilciyi kaldırma ve harcama izinlerini iptal etme.
Token transferiToken hesapları arasında token transferi yapma.

Is this page helpful?

İçindekiler

Sayfayı Düzenle

Yönetici

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