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

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

サブスクリプション権限は、プログラムが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つのサブスクリプション権限を作成してください。
  • 同じミントに対する後続の委任では、既存のサブスクリプション権限を再利用してください。
  • サブスクリプション権限に依存するすべての委任が取り消されるか閉じられた後にのみ、サブスクリプション権限を閉じてください。

Is this page helpful?

目次

ページを編集
© 2026 Solana Foundation. 無断転載を禁じます。