ClientPlugin
Defines a plugin that transforms or extends a client with additional functionality.
For instance, plugins may add RPC capabilities, wallet integration, transaction building, or other features necessary for interacting with the Solana blockchain.
Plugins are functions that take a client object as input and return a new client object or a promise that resolves to a new client object. This allows for both synchronous and asynchronous transformations and extensions of the client.
Plugins are usually applied using the use method on a Client or AsyncClient
instance, which createEmptyClient provides as a starting point.
Type Parameters
| Type Parameter | Description |
|---|---|
TInput extends object | The input client object type that this plugin accepts. |
TOutput extends | Promise<object> | object | The output type. Either a new client object or a promise resolving to one. |
Parameters
| Parameter | Type |
|---|---|
input | TInput |
Returns
TOutput
Examples
Given an RPC endpoint, this plugin adds an rpc property to the client.
The following plugin shows how to create an asynchronous plugin that generates a new keypair signer.
A plugin can specify required properties on the input client. The example below requires the
client to already have a payer signer attached to the client in order to perform an airdrop.
Multiple plugins — asynchronous or not — can be chained together to build up complex clients.
The example below demonstrates how to gradually build a client with multiple plugins.
Notice how, despite having multiple asynchronous plugins, we only need to await the final result.
This is because the use method on AsyncClient returns another AsyncClient, allowing for seamless chaining.