Interface: SolanaService
Solana service interface
Methods
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>
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 | TransactionSigner | Address; } | Optional configuration |
options.estimateComputeUnits? | boolean | If true, estimates and sets the compute unit limit. Default: false. |
options.feePayer? | string | TransactionSigner | Address | 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<number>;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<number>
The SOL balance in lamports as a number
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> & 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? | TransactionSigner | Optional payer for the account creation. If not provided, uses the wallet or service feePayer. |
Returns
Promise< | Instruction<Address, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]> & InstructionWithData<ReadonlyUint8Array> & 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 | - |