Interface: SolanaService
Solana service interface
Methods
airdrop()
airdrop(params): Promise<Signature>;Parameters
| Parameter | Type |
|---|---|
params | { amount: number | bigint; recipient: string | Address; } |
params.amount | number | bigint |
params.recipient | string | Address |
Returns
Promise<Signature>
buildAndSignBatch()
buildAndSignBatch(groups, options?): Promise<SignedBatchTransaction[]>;Pack instruction groups into the fewest transactions, then build and sign each — but do not broadcast. Returns one signed, base64-serialized transaction per bucket for a separate process to persist and send later. This is buildSignAndSendBatch minus the send: it exists so a consumer can persist-before-send for idempotency (a crash mid-send replays the identical signed transaction, which the chain dedups by signature).
Packing and the per-transaction compute-unit limit work exactly as in buildSignAndSendBatch. Each bucket is signed with all of its embedded signers (e.g. the fresh job/run keypairs minted by a list instruction) plus the fee payer — this is inherent to signing with the message's embedded signers, so every required signature is present in the returned blob.
Performs no network send. Each transaction is signed against its own freshly fetched blockhash, so lastValidBlockHeight may differ per bucket.
Because the transaction is signed now but may be broadcast later — potentially against a deeper, costlier state than when it was signed — the static compute-unit estimate can under-budget at land time. Use computeUnitMargin to over-provision the baked-in limit (the cost of over-budgeting is only fee, and for size-bound batches it does not reduce packing density).
Parameters
| Parameter | Type | Description |
|---|---|---|
groups | ( | Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]> | Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[])[] | Atomic instruction groups to bulk together. |
options? | { computeUnitMargin?: number; computeUnits?: number | (instruction) => number | undefined; estimateComputeUnits?: boolean; feePayer?: TransactionSigner; maxComputeUnits?: number; maxTransactionSize?: number; } | Same packing options as buildSignAndSendBatch (no commitment/sequential, which only apply to sending). |
options.computeUnitMargin? | number | Multiplier on each instruction's compute-unit estimate (default 1). Raise it (>1) to over-provision the limit for transactions broadcast later against a costlier state. |
options.computeUnits? | number | (instruction) => number | undefined | - |
options.estimateComputeUnits? | boolean | - |
options.feePayer? | TransactionSigner | - |
options.maxComputeUnits? | number | - |
options.maxTransactionSize? | number | - |
Returns
Promise<SignedBatchTransaction[]>
One signed, un-sent transaction per packed bucket, in packing order.
buildSignAndSend()
buildSignAndSend(instructions, options?): Promise<Signature>;Parameters
| Parameter | Type |
|---|---|
instructions | | Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]> | Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[] |
options? | { commitment?: "processed" | "confirmed" | "finalized"; estimateComputeUnits?: boolean; feePayer?: TransactionSigner; } |
options.commitment? | "processed" | "confirmed" | "finalized" |
options.estimateComputeUnits? | boolean |
options.feePayer? | TransactionSigner |
Returns
Promise<Signature>
buildSignAndSendBatch()
buildSignAndSendBatch(groups, options?): Promise<BatchTransactionResult[]>;Pack instruction groups into the fewest transactions that each stay within the Solana transaction size limit, then build, sign, and send all of them.
Each entry of groups is an atomic group: a single instruction, or an array of instructions that must stay together in the same transaction. Groups are never split across transactions; they are greedily packed into buckets sized by compiling each candidate transaction in-memory (no extra RPC calls).
Unless estimateComputeUnits is set, each transaction gets an explicit SetComputeUnitLimit equal to the sum of its instructions' estimated compute units (from computeUnits), capped at the 1.4M per-transaction maximum. This keeps priority fees — which are charged against the compute-unit limit — tight instead of being billed against Solana's inflated per-instruction default.
All transactions are attempted regardless of individual failures — the returned array reports the per-transaction outcome in input order.
Parameters
| Parameter | Type | Description |
|---|---|---|
groups | ( | Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]> | Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[])[] | Atomic instruction groups to bulk together. |
options? | { commitment?: "processed" | "confirmed" | "finalized"; computeUnitMargin?: number; computeUnits?: number | (instruction) => number | undefined; estimateComputeUnits?: boolean; feePayer?: TransactionSigner; maxComputeUnits?: number; maxTransactionSize?: number; sequential?: boolean; } | Optional configuration. |
options.commitment? | "processed" | "confirmed" | "finalized" | Commitment level for confirmation. |
options.computeUnitMargin? | number | - |
options.computeUnits? | number | (instruction) => number | undefined | Per-instruction compute-unit estimate: a fixed number for every instruction, or a function mapping an instruction to its units (return undefined to fall back to the default). Used to set each transaction's compute-unit limit and to bound packing. Defaults to Solana's per-instruction default. |
options.estimateComputeUnits? | boolean | If true, estimates the compute unit limit per transaction via simulation instead of the static computeUnits estimate. Default: false. |
options.feePayer? | TransactionSigner | Optional fee payer signer. Defaults to the service feePayer or wallet. |
options.maxComputeUnits? | number | Per-transaction compute-unit cap. Defaults to 1,400,000. |
options.maxTransactionSize? | number | Override the maximum serialized transaction size in bytes. |
options.sequential? | boolean | If true, sends transactions one at a time, confirming each before the next. Combined with estimateComputeUnits, this makes each simulation reflect the chain state left by the prior transactions (e.g. a market queue that grows or shrinks across the batch). Default: false (all transactions are sent concurrently). |
Returns
Promise<BatchTransactionResult[]>
A per-transaction result array, in the order the buckets were packed.
buildTransaction()
buildTransaction(instructions, options?): Promise<TransactionMessage & TransactionMessageWithFeePayer<string> & TransactionMessageWithBlockhashLifetime>;Build a transaction message from instructions. This function creates a transaction message with fee payer, blockhash, and instructions.
Parameters
| Parameter | Type | Description |
|---|---|---|
instructions | | Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]> | Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[] | Single instruction or array of instructions |
options? | { estimateComputeUnits?: boolean; feePayer?: string | Address | TransactionSigner; } | Optional configuration |
options.estimateComputeUnits? | boolean | If true, estimates and sets the compute unit limit. Default: false. |
options.feePayer? | string | Address | TransactionSigner | Optional custom fee payer. Can be a TransactionSigner (for full signing) or an Address/string (for partial signing where feepayer signs later). Takes precedence over service feePayer and wallet. |
Returns
Promise<TransactionMessage & TransactionMessageWithFeePayer<string> & TransactionMessageWithBlockhashLifetime>
An unsigned transaction message ready to be signed
decompileTransaction()
decompileTransaction(transaction): Readonly<{
instructions: readonly Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[];
version: TransactionVersion;
}> & TransactionMessageWithFeePayer<string> & TransactionMessageWithLifetime;Decompile a transaction back to a transaction message. Use this to inspect/verify the content of a deserialized transaction before signing.
Note: Decompilation is lossy - some information like lastValidBlockHeight may not be fully reconstructed. The returned message is suitable for inspection but may not be suitable for re-signing without additional context.
Parameters
| Parameter | Type | Description |
|---|---|---|
transaction | Transaction | The compiled transaction to decompile |
Returns
Readonly<{ instructions: readonly Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[]; version: TransactionVersion; }> & TransactionMessageWithFeePayer<string> & TransactionMessageWithLifetime
The decompiled transaction message (with either blockhash or durable nonce lifetime)
deserializeTransaction()
deserializeTransaction(base64): Promise<Readonly<{
messageBytes: TransactionMessageBytes;
signatures: SignaturesMap;
}> & TransactionWithBlockhashLifetime>;Deserialize a base64 string back to a transaction. Use this to receive transactions from other parties.
Note: This method automatically restores the lastValidBlockHeight metadata that is lost during serialization by fetching the latest blockhash from the RPC.
Parameters
| Parameter | Type | Description |
|---|---|---|
base64 | string | The base64 encoded transaction string |
Returns
Promise<Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }> & TransactionWithBlockhashLifetime>
The deserialized transaction with restored lifetime metadata
getBalance()
getBalance(addressStr?): Promise<bigint>;Get the SOL balance for a specific address.
Parameters
| Parameter | Type | Description |
|---|---|---|
addressStr? | string | Address | Optional address to query. If not provided, uses the wallet address. |
Returns
Promise<bigint>
The SOL balance in lamports
Throws
If neither address nor wallet is provided
getBalanceInfo()
getBalanceInfo(addressStr?): Promise<SolBalanceInfo>;Get SOL balance metadata for a specific address.
Parameters
| Parameter | Type | Description |
|---|---|---|
addressStr? | string | Address | Optional address to query. If not provided, uses the wallet address. |
Returns
Exact lamports plus display-oriented SOL metadata
Throws
If neither address nor wallet is provided
getCreateATAInstructionIfNeeded()
getCreateATAInstructionIfNeeded(
ata,
mint,
owner,
payer?): Promise<
| Instruction<Address, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]> & InstructionWithData<ReadonlyUint8Array<ArrayBufferLike>> & InstructionWithAccounts<[AccountMeta<string> & object & AccountSignerMeta<string, TransactionSigner<string>>, WritableAccount<string>, ReadonlyAccount<string>]>
| null>;Get an instruction to create an associated token account if it doesn't exist. Checks if the ATA exists, and if not, returns an instruction to create it. Uses the idempotent version so it's safe to call even if the account already exists.
Parameters
| Parameter | Type | Description |
|---|---|---|
ata | Address | The associated token account address |
mint | Address | The token mint address |
owner | Address | The owner of the associated token account |
payer? | Address | TransactionSigner | Optional payer for the account creation. Can be a TransactionSigner (for full signing) or an Address (for deferred signing scenarios where the payer signs later). If not provided, uses the wallet or service feePayer. |
Returns
Promise< | Instruction<Address, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]> & InstructionWithData<ReadonlyUint8Array<ArrayBufferLike>> & InstructionWithAccounts<[AccountMeta<string> & object & AccountSignerMeta<string, TransactionSigner<string>>, WritableAccount<string>, ReadonlyAccount<string>]> | null>
An instruction to create the ATA if it doesn't exist, or null if it already exists
partiallySignTransaction()
partiallySignTransaction(transactionMessage): Promise<Readonly<{
messageBytes: TransactionMessageBytes;
signatures: SignaturesMap;
}> & TransactionWithBlockhashLifetime>;Partially sign a transaction message with the signers embedded in the transaction. The transaction message must already have a fee payer address set (via buildTransaction with an address). Signers are extracted from instructions in the message (e.g., transfer source signer). Use this when building transactions where the fee payer will sign later.
Parameters
| Parameter | Type | Description |
|---|---|---|
transactionMessage | TransactionMessage & TransactionMessageWithFeePayer<string> & TransactionMessageWithBlockhashLifetime | The transaction message to sign (must have fee payer address set and signers embedded in instructions) |
Returns
Promise<Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }> & TransactionWithBlockhashLifetime>
A partially signed transaction
pda()
pda(seeds, programId): Promise<Address>;Parameters
| Parameter | Type |
|---|---|
seeds | (string | Address)[] |
programId | Address |
Returns
Promise<Address>
sendTransaction()
sendTransaction(transaction, options?): Promise<Signature>;Parameters
| Parameter | Type |
|---|---|
transaction | FullySignedTransaction & TransactionWithinSizeLimit & Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }> & TransactionWithBlockhashLifetime |
options? | { commitment?: "processed" | "confirmed" | "finalized"; } |
options.commitment? | "processed" | "confirmed" | "finalized" |
Returns
Promise<Signature>
serializeTransaction()
serializeTransaction(transaction): string;Serialize a transaction to a base64 string. Works with both partially signed and fully signed transactions. Use this to transmit transactions to other parties (e.g., for fee payer signing).
Parameters
| Parameter | Type | Description |
|---|---|---|
transaction | Transaction | The transaction to serialize |
Returns
string
Base64 encoded wire transaction string
signTransaction()
signTransaction(transactionMessage): Promise<FullySignedTransaction & TransactionWithinSizeLimit & Readonly<{
messageBytes: TransactionMessageBytes;
signatures: SignaturesMap;
}> & TransactionWithBlockhashLifetime>;Parameters
| Parameter | Type |
|---|---|
transactionMessage | TransactionMessage & TransactionMessageWithFeePayer<string> & TransactionMessageWithBlockhashLifetime |
Returns
Promise<FullySignedTransaction & TransactionWithinSizeLimit & Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }> & TransactionWithBlockhashLifetime>
signTransactionWithSigners()
signTransactionWithSigners(transaction, signers): Promise<FullySignedTransaction & TransactionWithinSizeLimit & Readonly<{
messageBytes: TransactionMessageBytes;
signatures: SignaturesMap;
}> & TransactionWithBlockhashLifetime>;Sign a transaction with the provided signers. Use this when receiving a partially signed transaction that needs additional signatures. This adds signatures from the provided signers to the transaction.
Parameters
| Parameter | Type | Description |
|---|---|---|
transaction | Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }> & TransactionWithBlockhashLifetime | The transaction to sign (typically partially signed, received from another party) |
signers | Readonly<{ address: Address<string>; signTransactions: Promise<readonly Readonly<Record<Address, SignatureBytes>>[]>; }>[] | Array of TransactionPartialSigners to sign with |
Returns
Promise<FullySignedTransaction & TransactionWithinSizeLimit & Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }> & TransactionWithBlockhashLifetime>
The signed transaction with additional signatures
transfer()
transfer(params): Promise<TransferSolInstruction<Address, string, string, []>>;Get an instruction to transfer SOL from one address to another.
Parameters
| Parameter | Type | Description |
|---|---|---|
params | { amount: number | bigint; from?: TransactionSigner; to: string | Address; } | Transfer parameters |
params.amount | number | bigint | Amount in lamports (number or bigint) |
params.from? | TransactionSigner | Optional sender TransactionSigner. If not provided, uses wallet from client. |
params.to | string | Address | Recipient address |
Returns
Promise<TransferSolInstruction<Address, string, string, []>>
An instruction to transfer SOL
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
config | readonly | SolanaConfig | - |
estimateAndSetComputeUnitLimit | readonly | <T>(transactionMessage) => Promise<AppendTransactionMessageInstructions<T, readonly [SetComputeUnitLimitInstruction<Address, []>]>> | - |
feePayer | public | TransactionSigner | undefined | Optional fee payer for transactions. If set, will be used as fallback when no feePayer is provided in options. Set this property directly to configure the fee payer. |
rpc | readonly | | Rpc<SolanaRpcApiForAllClusters | SolanaRpcApiForTestClusters> | RpcDevnet<SolanaRpcApiForAllClusters | SolanaRpcApiForTestClusters> | RpcMainnet<SolanaRpcApiForAllClusters | SolanaRpcApiForTestClusters> | RpcTestnet<SolanaRpcApiForAllClusters | SolanaRpcApiForTestClusters> | - |
rpcSubscriptions | readonly | | RpcSubscriptions<SolanaRpcSubscriptionsApi> | RpcSubscriptionsDevnet<SolanaRpcSubscriptionsApi> | RpcSubscriptionsMainnet<SolanaRpcSubscriptionsApi> | RpcSubscriptionsTestnet<SolanaRpcSubscriptionsApi> | - |
sendAndConfirmTransaction | readonly | SendAndConfirmTransactionWithBlockhashLifetimeFunction | - |