@solana/plugin-interfaces
Advanced tools
| import { Lamports } from '@solana/rpc-types'; | ||
| /** | ||
| * Configuration options for {@link ClientWithGetMinimumBalance.getMinimumBalance}. | ||
| */ | ||
| export type GetMinimumBalanceConfig = { | ||
| /** | ||
| * When `true`, the 128-byte account header is not added to the provided `space` value. | ||
| * | ||
| * By default, the account header (128 bytes) is included in the minimum balance computation | ||
| * on top of the provided `space`. Set this to `true` if the provided `space` already accounts | ||
| * for the header or if you want the minimum balance for the data portion only. | ||
| * | ||
| * @see {@link @solana/accounts#BASE_ACCOUNT_SIZE | BASE_ACCOUNT_SIZE} for the account header size constant. | ||
| */ | ||
| withoutHeader?: boolean; | ||
| }; | ||
| /** | ||
| * Represents a client that can compute the minimum balance required for an account to be | ||
| * exempt from deletion. | ||
| * | ||
| * Different implementations may compute this value differently — for example, by calling the | ||
| * `getMinimumBalanceForRentExemption` RPC method, or by using a locally cached value. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * async function logAccountCost(client: ClientWithGetMinimumBalance, dataSize: number) { | ||
| * const minimumBalance = await client.getMinimumBalance(dataSize); | ||
| * console.log(`Minimum balance for ${dataSize} bytes: ${minimumBalance} lamports`); | ||
| * } | ||
| * ``` | ||
| */ | ||
| export type ClientWithGetMinimumBalance = { | ||
| /** | ||
| * Computes the minimum lamports required for an account with the given data size. | ||
| * | ||
| * By default, the 128-byte account header is added on top of the provided `space`. Pass | ||
| * `{ withoutHeader: true }` to skip adding the header bytes. | ||
| * | ||
| * @param space - The number of bytes of account data. | ||
| * @param config - Optional configuration for the computation. | ||
| * @returns A promise resolving to the minimum {@link Lamports} required. | ||
| * | ||
| * @see {@link @solana/accounts#BASE_ACCOUNT_SIZE | BASE_ACCOUNT_SIZE} for the account header size constant. | ||
| */ | ||
| getMinimumBalance: (space: number, config?: GetMinimumBalanceConfig) => Promise<Lamports>; | ||
| }; | ||
| //# sourceMappingURL=get-minimum-balance.d.ts.map |
| {"version":3,"file":"get-minimum-balance.d.ts","sourceRoot":"","sources":["../../src/get-minimum-balance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IAClC;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACtC;;;;;;;;;;;OAWG;IACH,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,uBAAuB,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC7F,CAAC"} |
| import { Lamports } from '@solana/rpc-types'; | ||
| /** | ||
| * Configuration options for {@link ClientWithGetMinimumBalance.getMinimumBalance}. | ||
| */ | ||
| export type GetMinimumBalanceConfig = { | ||
| /** | ||
| * When `true`, the 128-byte account header is not added to the provided `space` value. | ||
| * | ||
| * By default, the account header (128 bytes) is included in the minimum balance computation | ||
| * on top of the provided `space`. Set this to `true` if the provided `space` already accounts | ||
| * for the header or if you want the minimum balance for the data portion only. | ||
| * | ||
| * @see {@link @solana/accounts#BASE_ACCOUNT_SIZE | BASE_ACCOUNT_SIZE} for the account header size constant. | ||
| */ | ||
| withoutHeader?: boolean; | ||
| }; | ||
| /** | ||
| * Represents a client that can compute the minimum balance required for an account to be | ||
| * exempt from deletion. | ||
| * | ||
| * Different implementations may compute this value differently — for example, by calling the | ||
| * `getMinimumBalanceForRentExemption` RPC method, or by using a locally cached value. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * async function logAccountCost(client: ClientWithGetMinimumBalance, dataSize: number) { | ||
| * const minimumBalance = await client.getMinimumBalance(dataSize); | ||
| * console.log(`Minimum balance for ${dataSize} bytes: ${minimumBalance} lamports`); | ||
| * } | ||
| * ``` | ||
| */ | ||
| export type ClientWithGetMinimumBalance = { | ||
| /** | ||
| * Computes the minimum lamports required for an account with the given data size. | ||
| * | ||
| * By default, the 128-byte account header is added on top of the provided `space`. Pass | ||
| * `{ withoutHeader: true }` to skip adding the header bytes. | ||
| * | ||
| * @param space - The number of bytes of account data. | ||
| * @param config - Optional configuration for the computation. | ||
| * @returns A promise resolving to the minimum {@link Lamports} required. | ||
| * | ||
| * @see {@link @solana/accounts#BASE_ACCOUNT_SIZE | BASE_ACCOUNT_SIZE} for the account header size constant. | ||
| */ | ||
| getMinimumBalance: (space: number, config?: GetMinimumBalanceConfig) => Promise<Lamports>; | ||
| }; |
@@ -10,4 +10,5 @@ /** | ||
| export * from './instruction-plans'; | ||
| export * from './get-minimum-balance'; | ||
| export * from './payer'; | ||
| export * from './rpc'; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC"} |
+8
-8
| { | ||
| "name": "@solana/plugin-interfaces", | ||
| "version": "6.4.1-canary-20260319133445", | ||
| "version": "6.5.0-canary-20260319134241", | ||
| "description": "TypeScript interfaces for building pluggable Solana clients", | ||
@@ -32,9 +32,9 @@ "homepage": "https://www.solanakit.com/api#solanaplugin-interfaces", | ||
| "dependencies": { | ||
| "@solana/addresses": "6.4.1-canary-20260319133445", | ||
| "@solana/instruction-plans": "6.4.1-canary-20260319133445", | ||
| "@solana/keys": "6.4.1-canary-20260319133445", | ||
| "@solana/rpc-spec": "6.4.1-canary-20260319133445", | ||
| "@solana/rpc-subscriptions-spec": "6.4.1-canary-20260319133445", | ||
| "@solana/rpc-types": "6.4.1-canary-20260319133445", | ||
| "@solana/signers": "6.4.1-canary-20260319133445" | ||
| "@solana/addresses": "6.5.0-canary-20260319134241", | ||
| "@solana/instruction-plans": "6.5.0-canary-20260319134241", | ||
| "@solana/keys": "6.5.0-canary-20260319134241", | ||
| "@solana/rpc-spec": "6.5.0-canary-20260319134241", | ||
| "@solana/rpc-subscriptions-spec": "6.5.0-canary-20260319134241", | ||
| "@solana/rpc-types": "6.5.0-canary-20260319134241", | ||
| "@solana/signers": "6.5.0-canary-20260319134241" | ||
| }, | ||
@@ -41,0 +41,0 @@ "peerDependencies": { |
+86
-59
@@ -40,13 +40,14 @@ [![npm][npm-image]][npm-url] | ||
| ```ts | ||
| import { extendClient } from '@solana/plugin-core'; | ||
| import { ClientWithPayer } from '@solana/plugin-interfaces'; | ||
| function memoPlugin() { | ||
| return <T extends ClientWithPayer>(client: T) => ({ | ||
| ...client, | ||
| sendMemo: (message: string) => { | ||
| // Use client.payer as the fee payer for the memo transaction | ||
| const feePayer = client.payer; | ||
| // ... | ||
| }, | ||
| }); | ||
| return <T extends ClientWithPayer>(client: T) => | ||
| extendClient(client, { | ||
| sendMemo: (message: string) => { | ||
| // Use client.payer as the fee payer for the memo transaction | ||
| const feePayer = client.payer; | ||
| // ... | ||
| }, | ||
| }); | ||
| } | ||
@@ -60,14 +61,37 @@ ``` | ||
| ```ts | ||
| import { extendClient } from '@solana/plugin-core'; | ||
| import { ClientWithAirdrop, ClientWithPayer } from '@solana/plugin-interfaces'; | ||
| function faucetPlugin() { | ||
| return <T extends ClientWithAirdrop & ClientWithPayer>(client: T) => ({ | ||
| ...client, | ||
| fundMyself: async (amount: Lamports) => { | ||
| await client.airdrop(client.payer.address, amount); | ||
| }, | ||
| }); | ||
| return <T extends ClientWithAirdrop & ClientWithPayer>(client: T) => | ||
| extendClient(client, { | ||
| fundMyself: async (amount: Lamports) => { | ||
| await client.airdrop(client.payer.address, amount); | ||
| }, | ||
| }); | ||
| } | ||
| ``` | ||
| ### `ClientWithGetMinimumBalance` | ||
| Represents a client that can compute the minimum balance required for an account to be exempt from deletion. Different implementations may compute this differently — for example, by calling the `getMinimumBalanceForRentExemption` RPC method, or by using a locally cached value. | ||
| By default, the 128-byte account header is added on top of the provided `space`. Pass `{ withoutHeader: true }` to skip adding the header bytes. | ||
| ```ts | ||
| import { extendClient } from '@solana/plugin-core'; | ||
| import { ClientWithGetMinimumBalance } from '@solana/plugin-interfaces'; | ||
| function accountCreationPlugin() { | ||
| return <T extends ClientWithGetMinimumBalance>(client: T) => | ||
| extendClient(client, { | ||
| getAccountCreationCost: async (dataSize: number) => { | ||
| const minimumBalance = await client.getMinimumBalance(dataSize); | ||
| console.log(`Minimum balance for ${dataSize} bytes: ${minimumBalance} lamports`); | ||
| return minimumBalance; | ||
| }, | ||
| }); | ||
| } | ||
| ``` | ||
| ### `ClientWithRpc<TRpcMethods>` | ||
@@ -78,2 +102,3 @@ | ||
| ```ts | ||
| import { extendClient } from '@solana/plugin-core'; | ||
| import { ClientWithRpc } from '@solana/plugin-interfaces'; | ||
@@ -83,9 +108,9 @@ import { GetBalanceApi } from '@solana/rpc-api'; | ||
| function balancePlugin() { | ||
| return <T extends ClientWithRpc<GetBalanceApi>>(client: T) => ({ | ||
| ...client, | ||
| getBalance: async (address: Address): Promise<Lamports> => { | ||
| const { value } = await client.rpc.getBalance(address).send(); | ||
| return value; | ||
| }, | ||
| }); | ||
| return <T extends ClientWithRpc<GetBalanceApi>>(client: T) => | ||
| extendClient(client, { | ||
| getBalance: async (address: Address): Promise<Lamports> => { | ||
| const { value } = await client.rpc.getBalance(address).send(); | ||
| return value; | ||
| }, | ||
| }); | ||
| } | ||
@@ -99,2 +124,3 @@ ``` | ||
| ```ts | ||
| import { extendClient } from '@solana/plugin-core'; | ||
| import { ClientWithRpcSubscriptions } from '@solana/plugin-interfaces'; | ||
@@ -104,11 +130,11 @@ import { AccountNotificationsApi } from '@solana/rpc-subscriptions-api'; | ||
| function accountWatcherPlugin() { | ||
| return <T extends ClientWithRpcSubscriptions<AccountNotificationsApi>>(client: T) => ({ | ||
| ...client, | ||
| onAccountChange: async (address: Address, callback: (lamports: Lamports) => void) => { | ||
| const subscription = await client.rpcSubscriptions.accountNotifications(address).subscribe(); | ||
| for await (const notification of subscription) { | ||
| callback(notification.value.lamports); | ||
| } | ||
| }, | ||
| }); | ||
| return <T extends ClientWithRpcSubscriptions<AccountNotificationsApi>>(client: T) => | ||
| extendClient(client, { | ||
| onAccountChange: async (address: Address, callback: (lamports: Lamports) => void) => { | ||
| const subscription = await client.rpcSubscriptions.accountNotifications(address).subscribe(); | ||
| for await (const notification of subscription) { | ||
| callback(notification.value.lamports); | ||
| } | ||
| }, | ||
| }); | ||
| } | ||
@@ -123,12 +149,13 @@ ``` | ||
| import { flattenTransactionPlan } from '@solana/instruction-plans'; | ||
| import { extendClient } from '@solana/plugin-core'; | ||
| import { ClientWithTransactionPlanning } from '@solana/plugin-interfaces'; | ||
| function transactionCounterPlugin() { | ||
| return <T extends ClientWithTransactionPlanning>(client: T) => ({ | ||
| ...client, | ||
| countTransactions: async (instructions: IInstruction[]) => { | ||
| const plan = await client.planTransactions(instructions); | ||
| return flattenTransactionPlan(plan).length; | ||
| }, | ||
| }); | ||
| return <T extends ClientWithTransactionPlanning>(client: T) => | ||
| extendClient(client, { | ||
| countTransactions: async (instructions: IInstruction[]) => { | ||
| const plan = await client.planTransactions(instructions); | ||
| return flattenTransactionPlan(plan).length; | ||
| }, | ||
| }); | ||
| } | ||
@@ -142,17 +169,18 @@ ``` | ||
| ```ts | ||
| import { extendClient } from '@solana/plugin-core'; | ||
| import { ClientWithPayer, ClientWithTransactionSending } from '@solana/plugin-interfaces'; | ||
| function transferPlugin() { | ||
| return <T extends ClientWithPayer & ClientWithTransactionSending>(client: T) => ({ | ||
| ...client, | ||
| transfer: async (recipient: Address, amount: Lamports) => { | ||
| const instruction = getTransferSolInstruction({ | ||
| source: client.payer, | ||
| destination: recipient, | ||
| amount, | ||
| }); | ||
| const result = await client.sendTransaction(instruction); | ||
| return result.context.signature; | ||
| }, | ||
| }); | ||
| return <T extends ClientWithPayer & ClientWithTransactionSending>(client: T) => | ||
| extendClient(client, { | ||
| transfer: async (recipient: Address, amount: Lamports) => { | ||
| const instruction = getTransferSolInstruction({ | ||
| source: client.payer, | ||
| destination: recipient, | ||
| amount, | ||
| }); | ||
| const result = await client.sendTransaction(instruction); | ||
| return result.context.signature; | ||
| }, | ||
| }); | ||
| } | ||
@@ -166,2 +194,3 @@ ``` | ||
| ```ts | ||
| import { extendClient } from '@solana/plugin-core'; | ||
| import { ClientWithPayer, ClientWithRpc, ClientWithTransactionSending } from '@solana/plugin-interfaces'; | ||
@@ -171,13 +200,11 @@ import { GetAccountInfoApi } from '@solana/rpc-api'; | ||
| function tokenTransferPlugin() { | ||
| return <T extends ClientWithPayer & ClientWithRpc<GetAccountInfoApi> & ClientWithTransactionSending>( | ||
| client: T, | ||
| ) => ({ | ||
| ...client, | ||
| transferToken: async (mint: Address, recipient: Address, amount: bigint) => { | ||
| // Use client.rpc to fetch token accounts | ||
| // Use client.payer as the token owner | ||
| // Use client.sendTransaction to execute the transfer | ||
| }, | ||
| }); | ||
| return <T extends ClientWithPayer & ClientWithRpc<GetAccountInfoApi> & ClientWithTransactionSending>(client: T) => | ||
| extendClient(client, { | ||
| transferToken: async (mint: Address, recipient: Address, amount: bigint) => { | ||
| // Use client.rpc to fetch token accounts | ||
| // Use client.payer as the token owner | ||
| // Use client.sendTransaction to execute the transfer | ||
| }, | ||
| }); | ||
| } | ||
| ``` |
+1
-0
@@ -10,3 +10,4 @@ /** | ||
| export * from './instruction-plans'; | ||
| export * from './get-minimum-balance'; | ||
| export * from './payer'; | ||
| export * from './rpc'; |
36489
21.09%21
16.67%536
21.27%201
15.52%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated