The PreAuthorizedDebitReadClient component of the SDK is outlined in the interface found in our Github repo.
Instantiating a PreAuthorizedDebitReadClient
Mainnet
import { clusterApiUrl, Connection } from"@solana/web3.js";import { PreAuthorizedDebitReadClientImpl } from"@seabed-labs/pre-authorized-debit";// You can use any connection object you'd like, this is just an exampleconstconnection=newConnection(clusterApiUrl("mainnet-beta"));constreadClient=PreAuthorizedDebitReadClientImpl.mainnet(connection);
Devnet
import { clusterApiUrl, Connection } from"@solana/web3.js";import { PreAuthorizedDebitReadClientImpl } from"@seabed-labs/pre-authorized-debit";// You can use any connection object you'd like, this is just an exampleconstconnection=newConnection(clusterApiUrl("devnet"));constreadClient=PreAuthorizedDebitReadClientImpl.devnet(connection);
Custom
Point the read client to a custom deployment on any cluster:
import { clusterApiUrl, Connection } from"@solana/web3.js";import { PreAuthorizedDebitReadClientImpl } from"@seabed-labs/pre-authorized-debit";constconnection=newConnection(/* your connection args */);constCUSTOM_PAD_PROGRAM_ID=/* your custom program ID */;constreadClient=PreAuthorizedDebitReadClientImpl.custom( connection,CUSTOM_PAD_PROGRAM_ID);
Our IDL is already available as Typescript or JSON. If you'd like to directly fetch it on-chain, you can either run the script here or just use our SDK:
Fetch all Pre-Authorizations associated with a token account
Fetch all PreAuthorization accounts associated with a particular token account (you can specify one-time, recurring, or all types):
consttokenAccount:PublicKey=// token account pubkey;consttype="all";constpreAuthAccounts=awaitreadClient.fetchPreAuthorizationsForTokenAccount( tokenAccount,// pubkey type,// "oneTime" or "recurring" or "all");for (constaccountof preAuthAccounts) {// ... (access them similar to `fetchPreAuthorization` above)}
Fetch all Pre-Authorizations associated with a debit authority
Fetch all PreAuthorization accounts associated with a particular debit authority (you can specify one-time, recurring, or all types):
constdebitAuthority:PublicKey=// debit authority pubkey;consttype="all";constpreAuthAccounts=awaitreadClient.fetchPreAuthorizationsForDebitAuthority( debitAuthority,// pubkey type,// "oneTime" or "recurring" or "all");for (constaccountof preAuthAccounts) {// ... (access them similar to `fetchPreAuthorization` above)}
Fetch maximum debit amount for a Pre-Authorization
Fetch the maximum possible amount that can be debited by the debit authority for a given pre-authorization:
Fetch the current delegation of a Pre-Authorization's token account
Fetch the current delegate and delegated amount of a token account given the pre-authorization public key (returns null if no delegate or delegated amount is 0):