支払いサブスクリプション

サブスクリプション権限の作成

サブスクリプション権限は、プログラムが1人のユーザーのtoken accountと1つのトークンミントに対してSPLトークンデリゲートとして使用するPDAです。そのミントに対して固定委任、定期委任、またはサブスクリプションプランのサブスクリプションを作成する前に作成してください。

ユーザーのtoken accountは既に存在している必要があります。初期化によってサブスクリプション権限PDAが作成され、ユーザーのtoken accountのトークンデリゲートとして承認されます。

権限の作成

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,
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 [userAta] = await findAssociatedTokenPda({
mint: tokenMint,
owner: userSigner.address,
tokenProgram: TOKEN_PROGRAM_ADDRESS,
});
const [subscriptionAuthorityPda] = await findSubscriptionAuthorityPda({
user: userSigner.address,
tokenMint,
});
const subscriptionAuthority = await fetchMaybeSubscriptionAuthority(
client.rpc,
subscriptionAuthorityPda,
);
if (!subscriptionAuthority.exists) {
await client.subscriptions.instructions
.initSubscriptionAuthority({
tokenMint,
tokenProgram: TOKEN_PROGRAM_ADDRESS,
userAta,
})
.sendTransaction();
}

注意事項

  • ユーザーが初期化トランザクションに署名します。
  • ユーザーとトークンミントのペアごとに1つのSubscription Authorityを作成します。
  • 同じミントに対する後続のデリゲーションでは、既存のSubscription Authorityを再利用します。
  • スポンサーがアカウントに資金を提供できます:initSubscriptionAuthorityにオプションのpayerを渡すか(createFixedDelegationcreateRecurringDelegationsubscribeでもサポート)、.use(payer(sponsorSigner))で設定します。その後、対応するreceiverでクローズするとrentがそのスポンサーに返還されます。自己資金調達のデフォルトを使用する場合は省略してください。
  • Subscription Authorityに依存するすべてのデリゲーションが取り消されるかクローズされた後にのみ、Subscription Authorityをクローズしてください。

Is this page helpful?

目次

ページを編集
© 2026 Solana Foundation. 無断転載を禁じます。
サブスクリプション権限の作成 | Solana