ÖdemelerAbonelikler

Yinelenen Yetkilendirme

Yinelenen yetkilendirme, bir kullanıcının başka bir cüzdan veya hizmetin her dönemde sıfırlanan bir limite kadar çekim yapmasına izin vermesini sağlar.

Bu kılavuz, hareketli parçaları görünür tutar. Önce hesapları türetir, gerekirse Abonelik Yetkisini başlatır, yinelenen yetkilendirmeyi oluşturur ve ardından transferler için bu yetkilendirme PDA'sını kullanırsınız.

Kurulum

pnpm add @solana/subscriptions @solana/kit @solana/kit-plugin-rpc @solana/kit-plugin-signer @solana-program/token

Yetkilendirmeyi Oluşturma

Kurulum dört bölümden oluşur:

  1. Kullanıcı imzalayıcısı ve abonelikler eklentisi ile bir istemci oluşturun.
  2. Kullanıcının token hesabını, Abonelik Yetkisi PDA'sını ve yinelenen yetkilendirme PDA'sını türetin.
  3. Abonelik Yetkisi henüz mevcut değilse başlatın.
  4. Dönem tutarı, dönem uzunluğu, başlangıç zamanı ve son kullanma tarihi ile yinelenen yetkilendirmeyi oluşturun.
import { address, createClient } from '@solana/kit';
import { solanaLocalRpc } from '@solana/kit-plugin-rpc';
import { signer } from '@solana/kit-plugin-signer';
import { findAssociatedTokenPda, TOKEN_PROGRAM_ADDRESS } from '@solana-program/token';
import {
fetchMaybeSubscriptionAuthority,
findRecurringDelegationPda,
findSubscriptionAuthorityPda,
subscriptionsProgram,
} from '@solana/subscriptions';
const client = createClient()
.use(signer(userSigner))
.use(solanaLocalRpc({ rpcUrl: 'http://127.0.0.1:8899' }))
.use(subscriptionsProgram());
const tokenMint = address('TOKEN_MINT_ADDRESS_HERE');
const delegatee = address('DELEGATEE_WALLET_ADDRESS_HERE');
const now = BigInt(Math.floor(Date.now() / 1000));
const nonce = 0n;
const amountPerPeriod = 1_000_000n;
const periodLengthS = 86_400n;
const startTs = now;
const expiryTs = now + periodLengthS * 30n;
const [userAta] = await findAssociatedTokenPda({
mint: tokenMint,
owner: userSigner.address,
tokenProgram: TOKEN_PROGRAM_ADDRESS,
});
const [subscriptionAuthorityPda] = await findSubscriptionAuthorityPda({
user: userSigner.address,
tokenMint,
});
const [delegationPda] = await findRecurringDelegationPda({
subscriptionAuthority: subscriptionAuthorityPda,
delegator: userSigner.address,
delegatee,
nonce,
});
const subscriptionAuthority = await fetchMaybeSubscriptionAuthority(
client.rpc,
subscriptionAuthorityPda,
);
if (!subscriptionAuthority.exists) {
await client.subscriptions.instructions
.initSubscriptionAuthority({
tokenMint,
tokenProgram: TOKEN_PROGRAM_ADDRESS,
userAta,
})
.sendTransaction();
}
await client.subscriptions.instructions
.createRecurringDelegation({
tokenMint,
delegatee,
nonce,
amountPerPeriod,
periodLengthS,
startTs,
expiryTs,
})
.sendTransaction();

Yetkilendirmeden Transfer Yapma

Yetkilendirilen taraf her transferi imzalar. Program mevcut dönemi kontrol eder ve dönemin kalan limitini aşacak transferleri reddeder.

const receiverAta = address('RECEIVER_TOKEN_ACCOUNT_ADDRESS_HERE');
await client.subscriptions.instructions
.transferRecurring({
delegatee: delegateeSigner,
delegator: userSigner.address,
delegatorAta: userAta,
tokenMint,
delegationPda,
amount: 100_000n,
receiverAta,
tokenProgram: TOKEN_PROGRAM_ADDRESS,
})
.sendTransaction();

Delegasyonu İptal Etme

Delegatör, tekrarlayan delegasyonu istediği zaman iptal edebilir. İptal işlemi, delegasyon PDA'sını kapatır ve rent'ini imzalayana geri döndürür.

await client.subscriptions.instructions
.revokeDelegation({
authority: userSigner,
delegationAccount: delegationPda,
})
.sendTransaction();

Notlar

  • amountPerPeriod temel birimlerle ifade edilir. 6 ondalıklı bir token için, 1_000_000 değeri 1 token anlamına gelir.
  • Program, mevcut dönemin kalan limitini aşan transferleri reddeder.
  • Bir sonraki dönem başladığında, çekilen miktar sıfırlanır.
  • Kullanıcı kurulum ve iptal işlemlerini imzalar. Delegatee transfer işlemlerini imzalar.

Is this page helpful?

İçindekiler

Sayfayı Düzenle
© 2026 Solana Vakfı. Tüm hakları saklıdır.