API Reference
Complete API documentation for @tetherto/wdk-wallet-solana
API Reference
Table of Contents
| Class | Description | Methods |
|---|---|---|
| WalletManagerSolana | Extends @tetherto/wdk-wallet. | Constructor, Methods, Properties |
| WalletAccountReadOnlySolana | Read-only Solana wallet account implementation. | Constructor, Methods, Properties |
| WalletAccountSolana | Extends @tetherto/wdk-wallet-solana. | Constructor, Methods, Properties |
WalletManagerSolana
Extends @tetherto/wdk-wallet
Constructor
new WalletManagerSolana(seed, config?)Parameters
seed(string | Uint8Array<ArrayBufferLike>): The wallet's BIP-39 seed phrase.config(SolanaWalletConfig, optional): The configuration object.
Source
src/wallet-manager-solana.js#L45
Methods
| Method | Description | Returns | Throws |
|---|---|---|---|
dispose() | Disposes all the wallet accounts, erasing their private keys from the memory. | void | - |
getAccount(index) | Returns the wallet account at a specific index (see SLIP-0010). | Promise<WalletAccountSolana> | - |
getAccountByPath(path) | Returns the wallet account at a specific SLIP-0010 derivation path. | Promise<WalletAccountSolana> | - |
getFeeRates() | Returns the current fee rates. | Promise<FeeRates> | - |
(static) getRandomSeedPhrase(wordCount) | Returns a random BIP-39 seed phrase. | string | - |
(static) isValidSeedPhrase(seedPhrase) | Checks if a seed phrase is valid. | boolean | - |
dispose()
Disposes all the wallet accounts, erasing their private keys from the memory.
Returns
void
getAccount(index)
Returns the wallet account at a specific index (see SLIP-0010).
Parameters
index(number, optional): The index of the account to get (default: 0).
Returns
Promise<WalletAccountSolana> - The account.
Example
// Returns the account with derivation path m/44'/501'/index'/0'
const account = await wallet.getAccount(1);Source
src/wallet-manager-solana.js#L98
getAccountByPath(path)
Returns the wallet account at a specific SLIP-0010 derivation path.
Parameters
path(string): The derivation path (e.g. "0'/0'/0'").
Returns
Promise<WalletAccountSolana> - The account.
Example
// Returns the account with derivation path m/44'/501'/0'/0'/1'
const account = await wallet.getAccountByPath("0'/0'/1'");Source
src/wallet-manager-solana.js#L111
getFeeRates()
Returns the current fee rates.
Returns
Promise<FeeRates> - The fee rates (in lamports).
Source
src/wallet-manager-solana.js#L126
getRandomSeedPhrase(wordCount) (static)
Returns a random BIP-39 seed phrase.
Parameters
wordCount(12 | unknown, optional): The number of words in the seed phrase.
Returns
string - The seed phrase.
isValidSeedPhrase(seedPhrase) (static)
Checks if a seed phrase is valid.
Parameters
seedPhrase(string): The seed phrase.
Returns
boolean - True if the seed phrase is valid.
Properties
| Property | Type | Description |
|---|---|---|
seed | Uint8Array | The seed phrase of the wallet. |
WalletAccountReadOnlySolana
Read-only Solana wallet account implementation.
Extends @tetherto/wdk-wallet
Constructor
new WalletAccountReadOnlySolana(addr, config?)Parameters
addr(string): The account's address.config(Omit<SolanaWalletConfig, "transferMaxFee">, optional): The configuration object.
Source
src/wallet-account-read-only-solana.js#L85
Methods
| Method | Description | Returns | Throws |
|---|---|---|---|
_assertFeePayer(tx) | Asserts that any explicit transaction fee payer matches this wallet address. | Promise<void> | Yes |
_buildNativeTransferTransactionMessage(to, value) | Builds a transaction message for native SOL transfer. Creates a transfer instruction for sending SOL. | Promise<TransactionMessage> | - |
_buildSPLTransferTransactionMessage(token, recipient, amount) | Builds a transaction message for SPL token transfer. Creates instructions for ATA creation (if needed) and token transfer. | Promise<TransactionMessage> | - |
_ensureLifetime(tx) | Ensures the transaction has either a blockhash lifetime or a durable nonce lifetime. | Promise<SolanaTransaction> | - |
_getTransactionFee(transactionMessage) | Calculates the fee for a given transaction message. | Promise<bigint> | - |
getAddress() | Returns the account's address. | Promise<string> | - |
getBalance() | Returns the account's native SOL balance. | Promise<bigint> | - |
getTokenBalance(tokenAddress) | Returns the account balance for a specific SPL token. | Promise<bigint> | - |
getTokenBalances(tokenAddresses) | Returns the account balances for a list of SPL tokens. | Promise<Record<string, bigint>> | - |
getTransactionReceipt(hash) | Retrieves a transaction receipt by its signature | Promise<Readonly<object> & (Record<string, never> | { version: TransactionVersion; }) & { meta: Readonly<{ computeUnitsConsumed?: bigint; err: TransactionError; fee: Lamports; ... 7 more ...; status: TransactionStatus; }> & (Readonly<...> & (Record<...> | Readonly<...>)); transaction: Readonly<...> & (Readonly<...> & (Record<...> | Readonly<....> | - |
quoteSendTransaction(tx) | Quotes the costs of a send transaction operation. | Promise<Omit<TransactionResult, "hash">> | - |
quoteTransfer(options) | Quotes the costs of a transfer operation. | Promise<Omit<TransferResult, "hash">> | - |
verify(message, signature) | Verifies a message's signature. | Promise<boolean> | - |
_assertFeePayer(tx)
Asserts that any explicit transaction fee payer matches this wallet address.
Parameters
tx(SolanaTransaction): The transaction.
Returns
Promise<void> - Resolves when the transaction has no explicit fee payer or it matches this wallet address.
Throws
If the transaction fee payer does not match this wallet address.
Source
src/wallet-account-read-only-solana.js#L521
_buildNativeTransferTransactionMessage(to, value)
Builds a transaction message for native SOL transfer. Creates a transfer instruction for sending SOL.
Parameters
to(string): The recipient's address.value(number | bigint): The amount of SOL to send (in lamports).
Returns
Promise<TransactionMessage> - The constructed transaction message.
Source
src/wallet-account-read-only-solana.js#L420
_buildSPLTransferTransactionMessage(token, recipient, amount)
Builds a transaction message for SPL token transfer. Creates instructions for ATA creation (if needed) and token transfer.
Parameters
token(string): The SPL token mint address (base58-encoded public key).recipient(string): The recipient's wallet address (base58-encoded public key).amount(number | bigint): The amount to transfer in token's base units (must be ≤ 2^64-1).
Returns
Promise<TransactionMessage> - The constructed transaction message.
Source
src/wallet-account-read-only-solana.js#L340
_ensureLifetime(tx)
Ensures the transaction has either a blockhash lifetime or a durable nonce lifetime.
Parameters
tx(SolanaTransaction): The transaction.
Returns
Promise<SolanaTransaction> - The transaction with lifetime.
Source
src/wallet-account-read-only-solana.js#L501
_getTransactionFee(transactionMessage)
Calculates the fee for a given transaction message.
Parameters
transactionMessage(TransactionMessage): The transaction message to calculate fee for.
Returns
Promise<bigint> - The calculated transaction fee in lamports.
Source
src/wallet-account-read-only-solana.js#L453
getAddress()
Returns the account's address.
Returns
Promise<string> - The account's address.
getBalance()
Returns the account's native SOL balance.
Returns
Promise<bigint> - The sol balance (in lamports).
Source
src/wallet-account-read-only-solana.js#L135
getTokenBalance(tokenAddress)
Returns the account balance for a specific SPL token.
Parameters
tokenAddress(string): The smart contract address of the token.
Returns
Promise<bigint> - The token balance (in base unit).
Source
src/wallet-account-read-only-solana.js#L152
getTokenBalances(tokenAddresses)
Returns the account balances for a list of SPL tokens.
Parameters
tokenAddresses(string[]): The smart contract addresses of the tokens.
Returns
Promise<Record<string, bigint>> - A mapping of token addresses to their balances (in base units).
Source
src/wallet-account-read-only-solana.js#L186
getTransactionReceipt(hash)
Retrieves a transaction receipt by its signature
Parameters
hash(string): The transaction's hash.
Returns
Promise<Readonly<object> & (Record<string, never> | { version: TransactionVersion; }) & { meta: Readonly<{ computeUnitsConsumed?: bigint; err: TransactionError; fee: Lamports; ... 7 more ...; status: TransactionStatus; }> & (Readonly<...> & (Record<...> | Readonly<...>)); transaction: Readonly<...> & (Readonly<...> & (Record<...> | Readonly<....> - — The receipt, or null if the transaction has not been included in a block yet.
Source
src/wallet-account-read-only-solana.js#L309
quoteSendTransaction(tx)
Quotes the costs of a send transaction operation.
Parameters
tx(SolanaTransaction): The transaction.
Returns
Promise<Omit<TransactionResult, "hash">> - The transaction's quotes.
Source
src/wallet-account-read-only-solana.js#L260
quoteTransfer(options)
Quotes the costs of a transfer operation.
Parameters
options(TransferOptions): The transfer's options.
Returns
Promise<Omit<TransferResult, "hash">> - The transfer's quotes.
Source
src/wallet-account-read-only-solana.js#L290
verify(message, signature)
Verifies a message's signature.
Parameters
message(string): The original message.signature(string): The signature to verify.
Returns
Promise<boolean> - True if the signature is valid.
Source
src/wallet-account-read-only-solana.js#L482
Properties
| Property | Type | Description |
|---|---|---|
_address | string | The account's address. |
WalletAccountSolana
Extends @tetherto/wdk-wallet-solana
Constructor
new WalletAccountSolana(seed, path, config?)Parameters
seed(string | Uint8Array<ArrayBufferLike>): The wallet's BIP-39 seed phrase.path(string): The SLIP-0010 derivation path (e.g. "0'/0'/0'").config(SolanaWalletConfig, optional): The configuration object.
Source
src/wallet-account-solana.js#L77
Methods
| Method | Description | Returns | Throws |
|---|---|---|---|
_assertFeePayer(tx) | Asserts that any explicit transaction fee payer matches this wallet address. | Promise<void> | Yes |
_buildNativeTransferTransactionMessage(to, value) | Builds a transaction message for native SOL transfer. Creates a transfer instruction for sending SOL. | Promise<TransactionMessage> | - |
_buildSPLTransferTransactionMessage(token, recipient, amount) | Builds a transaction message for SPL token transfer. Creates instructions for ATA creation (if needed) and token transfer. | Promise<TransactionMessage> | - |
_ensureLifetime(tx) | Ensures the transaction has either a blockhash lifetime or a durable nonce lifetime. | Promise<SolanaTransaction> | - |
_getTransactionFee(transactionMessage) | Calculates the fee for a given transaction message. | Promise<bigint> | - |
dispose() | Disposes the wallet account, erasing the private key from the memory. | void | - |
getAddress() | The address of this account. | Promise<string> | - |
getBalance() | Returns the account's native SOL balance. | Promise<bigint> | - |
getTokenBalance(tokenAddress) | Returns the account balance for a specific SPL token. | Promise<bigint> | - |
getTokenBalances(tokenAddresses) | Returns the account balances for a list of SPL tokens. | Promise<Record<string, bigint>> | - |
getTransactionReceipt(hash) | Retrieves a transaction receipt by its signature | Promise<Readonly<object> & (Record<string, never> | { version: TransactionVersion; }) & { meta: Readonly<{ computeUnitsConsumed?: bigint; err: TransactionError; fee: Lamports; ... 7 more ...; status: TransactionStatus; }> & (Readonly<...> & (Record<...> | Readonly<...>)); transaction: Readonly<...> & (Readonly<...> & (Record<...> | Readonly<....> | - |
quoteSendTransaction(tx) | Quotes the costs of a send transaction operation. | Promise<Omit<TransactionResult, "hash">> | - |
quoteTransfer(options) | Quotes the costs of a transfer operation. | Promise<Omit<TransferResult, "hash">> | - |
sendTransaction(tx) | Sends a transaction. | Promise<TransactionResult> | - |
sign(message) | Signs a message. | Promise<string> | - |
signTransaction(tx) | Signs a transaction. | Promise<FullySignedTransaction> | - |
toReadOnlyAccount() | Returns a read-only copy of the account. | Promise<WalletAccountReadOnlySolana> | - |
transfer(options) | Transfers a token to another address. | Promise<TransferResult> | - |
verify(message, signature) | Verifies a message's signature. | Promise<boolean> | - |
(static) at(seed, path, config) | Creates a new solana wallet account. | Promise<WalletAccountSolana> | - |
_assertFeePayer(tx)
Asserts that any explicit transaction fee payer matches this wallet address.
Parameters
tx(SolanaTransaction): The transaction.
Returns
Promise<void> - Resolves when the transaction has no explicit fee payer or it matches this wallet address.
Throws
If the transaction fee payer does not match this wallet address.
Source
src/wallet-account-read-only-solana.js#L521
_buildNativeTransferTransactionMessage(to, value)
Builds a transaction message for native SOL transfer. Creates a transfer instruction for sending SOL.
Parameters
to(string): The recipient's address.value(number | bigint): The amount of SOL to send (in lamports).
Returns
Promise<TransactionMessage> - The constructed transaction message.
Source
src/wallet-account-read-only-solana.js#L420
_buildSPLTransferTransactionMessage(token, recipient, amount)
Builds a transaction message for SPL token transfer. Creates instructions for ATA creation (if needed) and token transfer.
Parameters
token(string): The SPL token mint address (base58-encoded public key).recipient(string): The recipient's wallet address (base58-encoded public key).amount(number | bigint): The amount to transfer in token's base units (must be ≤ 2^64-1).
Returns
Promise<TransactionMessage> - The constructed transaction message.
Source
src/wallet-account-read-only-solana.js#L340
_ensureLifetime(tx)
Ensures the transaction has either a blockhash lifetime or a durable nonce lifetime.
Parameters
tx(SolanaTransaction): The transaction.
Returns
Promise<SolanaTransaction> - The transaction with lifetime.
Source
src/wallet-account-read-only-solana.js#L501
_getTransactionFee(transactionMessage)
Calculates the fee for a given transaction message.
Parameters
transactionMessage(TransactionMessage): The transaction message to calculate fee for.
Returns
Promise<bigint> - The calculated transaction fee in lamports.
Source
src/wallet-account-read-only-solana.js#L453
dispose()
Disposes the wallet account, erasing the private key from the memory.
Returns
void
Source
src/wallet-account-solana.js#L332
getAddress()
The address of this account.
Returns
Promise<string> - The address.
Source
src/wallet-account-solana.js#L194
getBalance()
Returns the account's native SOL balance.
Returns
Promise<bigint> - The sol balance (in lamports).
Source
src/wallet-account-read-only-solana.js#L135
getTokenBalance(tokenAddress)
Returns the account balance for a specific SPL token.
Parameters
tokenAddress(string): The smart contract address of the token.
Returns
Promise<bigint> - The token balance (in base unit).
Source
src/wallet-account-read-only-solana.js#L152
getTokenBalances(tokenAddresses)
Returns the account balances for a list of SPL tokens.
Parameters
tokenAddresses(string[]): The smart contract addresses of the tokens.
Returns
Promise<Record<string, bigint>> - A mapping of token addresses to their balances (in base units).
Source
src/wallet-account-read-only-solana.js#L186
getTransactionReceipt(hash)
Retrieves a transaction receipt by its signature
Parameters
hash(string): The transaction's hash.
Returns
Promise<Readonly<object> & (Record<string, never> | { version: TransactionVersion; }) & { meta: Readonly<{ computeUnitsConsumed?: bigint; err: TransactionError; fee: Lamports; ... 7 more ...; status: TransactionStatus; }> & (Readonly<...> & (Record<...> | Readonly<...>)); transaction: Readonly<...> & (Readonly<...> & (Record<...> | Readonly<....> - — The receipt, or null if the transaction has not been included in a block yet.
Source
src/wallet-account-read-only-solana.js#L309
quoteSendTransaction(tx)
Quotes the costs of a send transaction operation.
Parameters
tx(SolanaTransaction): The transaction.
Returns
Promise<Omit<TransactionResult, "hash">> - The transaction's quotes.
Source
src/wallet-account-read-only-solana.js#L260
quoteTransfer(options)
Quotes the costs of a transfer operation.
Parameters
options(TransferOptions): The transfer's options.
Returns
Promise<Omit<TransferResult, "hash">> - The transfer's quotes.
Source
src/wallet-account-read-only-solana.js#L290
sendTransaction(tx)
Sends a transaction.
Parameters
tx(SolanaTransaction): The transaction.
Returns
Promise<TransactionResult> - The transaction's result.
Source
src/wallet-account-solana.js#L244
sign(message)
Signs a message.
Parameters
message(string): The message to sign.
Returns
Promise<string> - The message's signature.
Source
src/wallet-account-solana.js#L205
signTransaction(tx)
Signs a transaction.
Parameters
tx(SolanaTransaction): The transaction to sign.
Returns
Promise<FullySignedTransaction> - The signed transaction.
Source
src/wallet-account-solana.js#L224
toReadOnlyAccount()
Returns a read-only copy of the account.
Returns
Promise<WalletAccountReadOnlySolana> - The read-only account.
Source
src/wallet-account-solana.js#L320
transfer(options)
Transfers a token to another address.
Parameters
options(TransferOptions): The transfer's options.
Returns
Promise<TransferResult> - The transfer's result.
Source
src/wallet-account-solana.js#L293
verify(message, signature)
Verifies a message's signature.
Parameters
message(string): The original message.signature(string): The signature to verify.
Returns
Promise<boolean> - True if the signature is valid.
Source
src/wallet-account-read-only-solana.js#L482
at(seed, path, config) (static)
Creates a new solana wallet account.
Parameters
seed(string | Uint8Array<ArrayBufferLike>): The wallet's BIP-39 seed phrase.path(string): The SLIP-0010 derivation path (e.g. "0'/0'/0'").config(SolanaWalletConfig, optional): The configuration object.
Returns
Promise<WalletAccountSolana> - The wallet account.
Source
src/wallet-account-solana.js#L150
Properties
| Property | Type | Description |
|---|---|---|
_address | string | The account's address. |
index | number | The derivation path's index of this account. |
keyPair | KeyPair | The account's key pair. The uint8 arrays are bound to the wallet account, so any external change will reflect to the internal representation. For this reason, it's strongly recommended to treat the key pair as a read-only view of the keys. While it's still technically possible to alter their content, client code should never do so. |
path | string | The derivation path of this account. |
Types
SimpleSolanaTransaction
| Property | Type | Description |
|---|---|---|
to | string | The recipient's Solana address. |
value | `number | bigint` |
Source
src/wallet-account-read-only-solana.js#L55
SolanaWalletConfig
| Property | Type | Description |
|---|---|---|
commitment? | Commitment | The commitment level (default: 'confirmed'). |
provider? | `string | string[]` |
retries? | number | If set and if 'provider' is a list of urls, the number of additional retry attempts after the initial call fails. Total attempts = 1 + retries. For example, retries: 3 with 4 providers will try each provider once before throwing. If retries exceeds the number of providers, the failover will loop back and retry already-failed providers in round-robin order (default: 3). |
rpcUrl? | `string | string[]` |
transferMaxFee? | `number | bigint` |