@solana/kit-plugin-payer
v0.6.0
Published
Payer helpers for Kit clients
Downloads
1,303
Maintainers
Readme
Kit Plugins ➤ Payer
This package offers plugins that set up the main "payer" signer on your Kit clients. It does this by adding a payer property to the client, which can then be used to sign transactions, pay for fees, etc. This is a good way to feed signer information to subsequent plugins.
Installation
pnpm install @solana/kit-plugin-payerpayer plugin
This plugin simply accepts a TransactionSigner and sets it as the payer property on the client.
Installation
import { createEmptyClient } from '@solana/kit';
import { payer } from '@solana/kit-plugins';
const client = createEmptyClient().use(payer(mySigner));Features
payer: The main payer signer for your Kit client.console.log(client.payer.address); const transactionMessage = pipe( createTransactionMessage({ version: 0 }), tx => setTransactionFeePayerSigner(client.payer, tx), tx => appendTransactionMessageInstruction(getTransferSolInstruction({ source: client.payer, ... }), tx), );
generatedPayer plugin
This asynchronous plugin generates a new random KeyPairSigner to be used as the payer property on the client.
Installation
import { createEmptyClient } from '@solana/kit';
import { generatedPayer } from '@solana/kit-plugins';
const client = await createEmptyClient().use(generatedPayer());Features
See the payer plugin for available features.
generatedPayerWithSol plugin
This asynchronous plugin generates a new random KeyPairSigner, airdrops some SOL to it and sets it as the payer property on the client.
Installation
Note that this plugin requires the airdrop plugin to be installed on the client beforehand which itself either requires an RPC connection or a LiteSVM instance.
import { createEmptyClient } from '@solana/kit';
import { airdrop, generatedPayerWithSol, localhostRpc } from '@solana/kit-plugins';
const client = await createEmptyClient()
.use(localhostRpc()) // or .use(litesvm())
.use(airdrop())
.use(generatedPayerWithSol(lamports(10_000_000_000n))); // 10 SOLFeatures
See the payer plugin for available features.
payerOrGeneratedPayer plugin
This asynchronous plugin uses the provided TransactionSigner as the payer if one is given. Otherwise, it generates a new random KeyPairSigner, airdrops 100 SOL to it, and sets it as the payer property on the client. This is useful when you want to optionally accept a payer from the caller but fall back to a generated and funded payer for convenience (e.g. in testing or local development).
Installation
When no explicit payer is given, this plugin requires the airdrop plugin to be installed on the client beforehand which itself either requires an RPC connection or a LiteSVM instance.
import { createEmptyClient } from '@solana/kit';
import { airdrop, localhostRpc, payerOrGeneratedPayer } from '@solana/kit-plugins';
// With an explicit payer — no airdrop needed.
const client = await createEmptyClient().use(payerOrGeneratedPayer(mySigner));
// Without a payer — generates one and airdrops 100 SOL.
const client = await createEmptyClient()
.use(localhostRpc()) // or .use(litesvm())
.use(airdrop())
.use(payerOrGeneratedPayer(undefined));Features
See the payer plugin for available features.
payerFromFile plugin
This plugin loads a KeyPairSigner from a local file and sets it as the payer property on the client.
Installation
Note that this plugin requires access to the local filesystem and therefore can only work in Node.js environments. Other environments (like browsers) will throw an error when trying to use this plugin.
import { createEmptyClient } from '@solana/kit';
import { payerFromFile } from '@solana/kit-plugins';
const client = createEmptyClient().use(payerFromFile('path/to/keypair.json'));Features
See the payer plugin for available features.
