WDK logoWDK documentation

Wallet Solana API Reference

Complete API documentation for @tetherto/wdk-wallet-solana

API Reference

Table of Contents

ClassDescriptionMethods
WalletManagerSolanaMain class for managing Solana wallets. Extends WalletManager from @tetherto/wdk-wallet.Constructor, Methods
WalletAccountSolanaIndividual Solana wallet account implementation. Extends WalletAccountReadOnlySolana and implements IWalletAccount.Constructor, Methods, Properties
WalletAccountReadOnlySolanaRead-only Solana wallet account.Constructor, Methods

WalletManagerSolana

The main class for managing Solana wallets.
Extends WalletManager from @tetherto/wdk-wallet.

Constructor

new WalletManagerSolana(seed, config)

Parameters:

  • seed (string | Uint8Array): BIP-39 mnemonic seed phrase or seed bytes
  • config (object): Configuration object
    • rpcUrl (string | string[]): RPC endpoint URL or an ordered list of endpoints for failover
    • commitment (string, optional): Commitment level ('processed', 'confirmed', or 'finalized')
    • retries (number, optional): Retry count for failover requests (default: 3)
    • transferMaxFee (number, optional): Maximum fee amount for transfer operations (in lamports)

Example:

const wallet = new WalletManagerSolana(seedPhrase, {
  rpcUrl: 'https://api.mainnet-beta.solana.com',
  commitment: 'confirmed',
  transferMaxFee: 5000 // Maximum fee in lamports
})

Methods

MethodDescriptionReturns
getAccount(index)Returns a wallet account at the specified indexPromise\<WalletAccountSolana\>
getAccountByPath(path)Returns a wallet account at the specified SLIP-0010 derivation pathPromise\<WalletAccountSolana\>
getFeeRates()Returns current fee rates for transactionsPromise\<{normal: bigint, fast: bigint}\>
dispose()Disposes all wallet accounts, clearing private keys from memoryvoid
getAccount(index)

Returns a wallet account at the specified index.

Parameters:

  • index (number, optional): The index of the account to get (default: 0)

Returns: Promise\<WalletAccountSolana\> - The wallet account

Example:

const account = await wallet.getAccount(0)
getAccountByPath(path)

Returns a wallet account at the specified SLIP-0010 derivation path.

Parameters:

  • path (string): The derivation path (e.g., "0'/0'/0'"). On Solana, every child segment must be hardened.

Returns: Promise\<WalletAccountSolana\> - The wallet account

Example:

const account = await wallet.getAccountByPath("0'/0'/1'")
getFeeRates()

Returns current fee rates for transactions based on recent prioritization fees.

Returns: Promise\<{normal: bigint, fast: bigint}\> - Object containing fee rates in lamports

Throws: Error if wallet is not connected to a provider

Example:

const feeRates = await wallet.getFeeRates()
console.log('Normal fee rate:', feeRates.normal, 'lamports')
console.log('Fast fee rate:', feeRates.fast, 'lamports')
dispose()

Disposes all wallet accounts, clearing private keys from memory.

Example:

wallet.dispose()

WalletAccountSolana

Represents an individual Solana wallet account. Extends WalletAccountReadOnlySolana and implements IWalletAccount.

Constructor

new WalletAccountSolana(seed, path, config)

Parameters:

  • seed (string | Uint8Array): BIP-39 mnemonic seed phrase or seed bytes
  • path (string): SLIP-0010 derivation path (e.g., "0'/0'/0'")
  • config (SolanaWalletConfig, optional): Configuration object

Methods

MethodDescriptionReturns
getAddress()Returns the account's Solana addressPromise\<string\>
sign(message)Signs a message using the account's private keyPromise\<string\>
verify(message, signature)Verifies a message signaturePromise\<boolean\>
sendTransaction(tx)Sends a Solana transactionPromise\<{hash: string, fee: bigint}\>
quoteSendTransaction(tx)Estimates the fee for a transactionPromise\<{fee: bigint}\>
transfer(options)Transfers SPL tokens to another addressPromise\<{hash: string, fee: bigint}\>
quoteTransfer(options)Estimates the fee for an SPL token transferPromise\<{fee: bigint}\>
getBalance()Returns the native SOL balance (in lamports)Promise\<bigint\>
getTokenBalance(tokenMint)Returns the balance of a specific SPL tokenPromise\<bigint\>
getTransactionReceipt(hash)Gets the transaction receipt for a given transaction hashPromise\<SolanaTransactionReceipt | null\>
toReadOnlyAccount()Returns a read-only copy of the accountPromise\<WalletAccountReadOnlySolana\>
dispose()Disposes the wallet account, clearing private keys from memoryvoid
getAddress()

Returns the account's Solana address.

Returns: Promise\<string\> - The account's base58-encoded Solana address

Example:

const address = await account.getAddress()
console.log('Account address:', address)
sign(message)

Signs a message using the account's private key.

Parameters:

  • message (string): The message to sign

Returns: Promise\<string\> - The message signature (hex-encoded)

Example:

const signature = await account.sign('Hello, Solana!')
console.log('Signature:', signature)
verify(message, signature)

Verifies a message signature against the account's address.

Parameters:

  • message (string): The original message
  • signature (string): The signature to verify (hex-encoded)

Returns: Promise\<boolean\> - True if the signature is valid

Example:

const isValid = await account.verify('Hello, Solana!', signature)
console.log('Signature valid:', isValid)
sendTransaction(tx)

Sends a Solana transaction.

Parameters:

  • tx (SolanaTransaction): A simple transfer object or a prebuilt TransactionMessage
    • to (string): Recipient's Solana address (base58-encoded)
    • value (number | bigint): Amount in lamports

When tx is a TransactionMessage, WDK preserves an existing recent blockhash or durable nonce lifetime. If no lifetime is present, WDK fetches the latest blockhash before quoting or sending. If you set an explicit feePayer, it must match the wallet address.

Returns: Promise\<{hash: string, fee: bigint}\> - Object containing transaction hash and fee (in lamports)

Throws: Error if wallet is not connected to a provider

Example:

const result = await account.sendTransaction({
  to: '11111111111111111111111111111112',
  value: 1000000000 // 1 SOL in lamports
})
console.log('Transaction hash:', result.hash)
console.log('Transaction fee:', result.fee, 'lamports')
quoteSendTransaction(tx)

Estimates the fee for a Solana transaction.

Parameters:

  • tx (SolanaTransaction): The transaction object (same as sendTransaction)

Returns: Promise\<{fee: bigint}\> - Object containing fee estimate (in lamports)

Example:

const quote = await account.quoteSendTransaction({
  to: '11111111111111111111111111111112',
  value: 1000000000
})
console.log('Estimated fee:', quote.fee, 'lamports')
transfer(options)

Transfers SPL tokens to another address.

Parameters:

  • options (TransferOptions): Transfer options
    • token (string): Token mint address (base58-encoded)
    • recipient (string): Recipient's Solana address (base58-encoded)
    • amount (number | bigint): Amount in token's base units

Returns: Promise\<{hash: string, fee: bigint}\> - Object containing transaction hash and fee (in lamports)

Throws: Error if wallet is not connected to a provider or if fee exceeds maximum

Example:

const result = await account.transfer({
  token: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB', // USDT mint
  recipient: '11111111111111111111111111111112',
  amount: 1000000 // 1 USDT (6 decimals)
})
console.log('Transfer hash:', result.hash)
console.log('Transfer fee:', result.fee, 'lamports')
quoteTransfer(options)

Estimates the fee for an SPL token transfer.

Parameters:

  • options (TransferOptions): Transfer options (same as transfer)

Returns: Promise\<{fee: bigint}\> - Object containing fee estimate (in lamports)

Example:

const quote = await account.quoteTransfer({
  token: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
  recipient: '11111111111111111111111111111112',
  amount: 1000000
})
console.log('Transfer fee estimate:', quote.fee, 'lamports')
getBalance()

Returns the native SOL balance (in lamports).

Returns: Promise\<bigint\> - Balance in lamports

Example:

const balance = await account.getBalance()
console.log('SOL balance:', balance, 'lamports')
getTokenBalance(tokenMint)

Returns the balance of a specific SPL token.

Parameters:

  • tokenMint (string): Token mint address (base58-encoded)

Returns: Promise\<bigint\> - Token balance in base units

Example:

const tokenBalance = await account.getTokenBalance('Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB')
console.log('USDT balance:', tokenBalance)
getTransactionReceipt(hash)

Gets the transaction receipt for a given transaction hash.

Parameters:

  • hash (string): Transaction hash

Returns: Promise\<SolanaTransactionReceipt | null\> - Transaction receipt details, or null if not found

Example:

const receipt = await account.getTransactionReceipt('5....')
console.log('Transaction receipt:', receipt)
toReadOnlyAccount()

Returns a read-only copy of the account.

Returns: Promise\<WalletAccountReadOnlySolana\> - The read-only account

Example:

const readOnlyAccount = await account.toReadOnlyAccount()
dispose()

Disposes the wallet account, clearing private keys from memory.

Example:

account.dispose()

Properties

PropertyTypeDescription
indexnumberThe derivation path's index of this account
pathstringThe full derivation path of this account
keyPair{publicKey: Buffer, privateKey: Buffer}The account's Ed25519 key pair

⚠️ Security Note: The keyPair property contains sensitive cryptographic material. Never log, display, or expose the private key.

WalletAccountReadOnlySolana

Represents a read-only Solana wallet account.

Constructor

new WalletAccountReadOnlySolana(publicKey, config)

Parameters:

  • publicKey (string): The account's public key (base58-encoded)
  • config (SolanaWalletConfig, optional): Configuration object

Methods

MethodDescriptionReturns
getAddress()Returns the account's Solana addressPromise\<string\>
getBalance()Returns the native SOL balance (in lamports)Promise\<bigint\>
getTokenBalance(tokenMint)Returns the balance of a specific SPL tokenPromise\<bigint\>
verify(message, signature)Verifies a message signaturePromise\<boolean\>
quoteSendTransaction(tx)Estimates the fee for a transactionPromise\<{fee: bigint}\>
quoteTransfer(options)Estimates the fee for an SPL token transferPromise\<{fee: bigint}\>
getAddress()

Returns the account's Solana address.

Returns: Promise\<string\> - The account's base58-encoded Solana address

Example:

const address = await readOnlyAccount.getAddress()
console.log('Account address:', address)
getBalance()

Returns the native SOL balance (in lamports).

Returns: Promise\<bigint\> - Balance in lamports

Example:

const balance = await readOnlyAccount.getBalance()
console.log('SOL balance:', balance, 'lamports')
getTokenBalance(tokenMint)

Returns the balance of a specific SPL token.

Parameters:

  • tokenMint (string): Token mint address (base58-encoded)

Returns: Promise\<bigint\> - Token balance in base units

Example:

const tokenBalance = await readOnlyAccount.getTokenBalance('Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB')
console.log('USDT balance:', tokenBalance)
verify(message, signature)

Verifies a message signature.

Parameters:

  • message (string): The original message
  • signature (string): The signature to verify (hex-encoded)

Returns: Promise\<boolean\> - True if the signature is valid

Example:

const isValid = await readOnlyAccount.verify('Hello, Solana!', signature)
console.log('Signature valid:', isValid)
quoteSendTransaction(tx)

Estimates the fee for a transaction.

Parameters:

  • tx (SolanaTransaction): The transaction object
    • to (string): Recipient's Solana address (base58-encoded)
    • value (number): Amount in lamports

Returns: Promise\<{fee: bigint}\> - Object containing fee estimate (in lamports)

Example:

const quote = await readOnlyAccount.quoteSendTransaction({
  to: '11111111111111111111111111111112',
  value: 1000000000
})
console.log('Estimated fee:', quote.fee, 'lamports')
quoteTransfer(options)

Estimates the fee for an SPL token transfer.

Parameters:

  • options (TransferOptions): Transfer options
    • token (string): Token mint address (base58-encoded)
    • recipient (string): Recipient's Solana address (base58-encoded)
    • amount (number): Amount in token's base units

Returns: Promise\<{fee: bigint}\> - Object containing fee estimate (in lamports)

Example:

const quote = await readOnlyAccount.quoteTransfer({
  token: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
  recipient: '11111111111111111111111111111112',
  amount: 1000000
})
console.log('Transfer fee estimate:', quote.fee, 'lamports')

Types

SolanaWalletConfig

interface SolanaWalletConfig {
  rpcUrl?: string | string[];
  commitment?: 'processed' | 'confirmed' | 'finalized';
  retries?: number;
  transferMaxFee?: number | bigint;
}

TransferOptions

interface TransferOptions {
  token: string;
  recipient: string;
  amount: number | bigint;
}

KeyPair

interface KeyPair {
  publicKey: Uint8Array
  privateKey: Uint8Array
}

Need Help?

On this page