Skip to content

Interface: SolanaService

Solana service interface

Methods

buildSignAndSend()

ts
buildSignAndSend(instructions, options?): Promise<Signature>;

Parameters

ParameterType
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()

ts
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

ParameterTypeDescription
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?booleanIf true, estimates and sets the compute unit limit. Default: false.
options.feePayer?string | TransactionSigner | AddressOptional 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()

ts
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

ParameterTypeDescription
transactionTransactionThe 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()

ts
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

ParameterTypeDescription
base64stringThe base64 encoded transaction string

Returns

Promise<Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }> & TransactionWithBlockhashLifetime>

The deserialized transaction with restored lifetime metadata


getBalance()

ts
getBalance(addressStr?): Promise<number>;

Get the SOL balance for a specific address.

Parameters

ParameterTypeDescription
addressStr?string | AddressOptional 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()

ts
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

ParameterTypeDescription
ataAddressThe associated token account address
mintAddressThe token mint address
ownerAddressThe owner of the associated token account
payer?TransactionSignerOptional 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()

ts
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

ParameterTypeDescription
transactionMessageTransactionMessage & TransactionMessageWithFeePayer<string> & TransactionMessageWithBlockhashLifetimeThe 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()

ts
pda(seeds, programId): Promise<Address>;

Parameters

ParameterType
seeds(string | Address)[]
programIdAddress

Returns

Promise<Address>


sendTransaction()

ts
sendTransaction(transaction, options?): Promise<Signature>;

Parameters

ParameterType
transactionFullySignedTransaction & TransactionWithinSizeLimit & Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }> & TransactionWithBlockhashLifetime
options?{ commitment?: "processed" | "confirmed" | "finalized"; }
options.commitment?"processed" | "confirmed" | "finalized"

Returns

Promise<Signature>


serializeTransaction()

ts
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

ParameterTypeDescription
transactionTransactionThe transaction to serialize

Returns

string

Base64 encoded wire transaction string


signTransaction()

ts
signTransaction(transactionMessage): Promise<FullySignedTransaction & TransactionWithinSizeLimit & Readonly<{
  messageBytes: TransactionMessageBytes;
  signatures: SignaturesMap;
}> & TransactionWithBlockhashLifetime>;

Parameters

ParameterType
transactionMessageTransactionMessage & TransactionMessageWithFeePayer<string> & TransactionMessageWithBlockhashLifetime

Returns

Promise<FullySignedTransaction & TransactionWithinSizeLimit & Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }> & TransactionWithBlockhashLifetime>


signTransactionWithSigners()

ts
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

ParameterTypeDescription
transactionReadonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }> & TransactionWithBlockhashLifetimeThe transaction to sign (typically partially signed, received from another party)
signersReadonly<{ 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()

ts
transfer(params): Promise<TransferSolInstruction<Address, string, string, []>>;

Get an instruction to transfer SOL from one address to another.

Parameters

ParameterTypeDescription
params{ amount: number | bigint; from?: TransactionSigner; to: string | Address; }Transfer parameters
params.amountnumber | bigintAmount in lamports (number or bigint)
params.from?TransactionSignerOptional sender TransactionSigner. If not provided, uses wallet from client.
params.tostring | AddressRecipient address

Returns

Promise<TransferSolInstruction<Address, string, string, []>>

An instruction to transfer SOL

Properties

PropertyModifierTypeDescription
configreadonlySolanaConfig-
estimateAndSetComputeUnitLimitreadonly<T>(transactionMessage) => Promise<AppendTransactionMessageInstructions<T, readonly [SetComputeUnitLimitInstruction<Address, []>]>>-
feePayerpublicTransactionSigner | undefinedOptional 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.
rpcreadonly| Rpc<SolanaRpcApiForAllClusters | SolanaRpcApiForTestClusters> | RpcDevnet<SolanaRpcApiForAllClusters | SolanaRpcApiForTestClusters> | RpcMainnet<SolanaRpcApiForAllClusters | SolanaRpcApiForTestClusters> | RpcTestnet<SolanaRpcApiForAllClusters | SolanaRpcApiForTestClusters>-
rpcSubscriptionsreadonly| RpcSubscriptions<SolanaRpcSubscriptionsApi> | RpcSubscriptionsDevnet<SolanaRpcSubscriptionsApi> | RpcSubscriptionsMainnet<SolanaRpcSubscriptionsApi> | RpcSubscriptionsTestnet<SolanaRpcSubscriptionsApi>-
sendAndConfirmTransactionreadonlySendAndConfirmTransactionWithBlockhashLifetimeFunction-