API Reference

Complete API documentation for @tetherto/wdk

Table of Contents

Class
Description
Methods

Main class for managing wallets across multiple blockchains. Orchestrates wallet managers and protocols.

Extended wallet account interface that supports protocol registration and access. Extends IWalletAccount.

WDK

The main class for managing wallets across multiple blockchains. This class serves as an orchestrator that allows you to register different wallet managers and protocols, providing a unified interface for multi-chain operations.

Constructor

Constructor
new WDK(seed)

Parameters:

  • seed (string | Uint8Array): BIP-39 mnemonic seed phrase or seed bytes

Example:

Initialize WDK
import WDK from '@tetherto/wdk'

// With seed phrase
const wdk = new WDK('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about')

// With seed bytes
const seedBytes = new Uint8Array([...])
const wdk2 = new WDK(seedBytes)

Methods

Method
Description
Returns
Throws

registerWallet(blockchain, wallet, config)

Registers a new wallet manager for a blockchain

WDK

-

registerProtocol(blockchain, label, protocol, config)

Registers a protocol globally for a blockchain

WDK

-

registerMiddleware(blockchain, middleware)

Registers middleware for account decoration

WDK

-

getAccount(blockchain, index?)

Returns a wallet account for a blockchain and index

Promise<IWalletAccountWithProtocols>

If wallet not registered

getAccountByPath(blockchain, path)

Returns a wallet account for a blockchain and derivation path

Promise<IWalletAccountWithProtocols>

If wallet not registered

getFeeRates()

Returns current fee rates

Promise<FeeRates>

-

dispose()

Disposes all wallets and accounts, clearing sensitive data

void

-

registerWallet(blockchain, wallet, config)

Registers a new wallet manager for a specific blockchain.

Type Parameters:

  • W: typeof WalletManager - A class that extends the @tetherto/wdk-wallet's WalletManager class

Parameters:

  • blockchain (string): The name of the blockchain (e.g., "ethereum", "ton", "bitcoin")

  • wallet (W): The wallet manager class

  • config (ConstructorParameters[1]): The configuration object for the wallet

Returns: WDK - The wdk manager instance (supports method chaining)

Example:

registerProtocol(blockchain, label, protocol, config)

Registers a protocol globally for all accounts of a specific blockchain.

Type Parameters:

  • P: typeof SwapProtocol | typeof BridgeProtocol | typeof LendingProtocol - A class that extends one of the @tetherto/wdk-wallet/protocol's classes

Parameters:

  • blockchain (string): The name of the blockchain

  • label (string): Unique label for the protocol (must be unique per blockchain and protocol type)

  • protocol (P): The protocol class

  • config (ConstructorParameters

    [1]): The protocol configuration

Returns: WDK - The wdk manager instance (supports method chaining)

Example:

registerMiddleware(blockchain, middleware)

Registers middleware for account decoration and enhanced functionality.

Parameters:

  • blockchain (string): The name of the blockchain

  • middleware (<A extends IWalletAccount>(account: A) => Promise<A | void>): Middleware function called when deriving accounts

Returns: WDK - The wdk manager instance (supports method chaining)

Example:

getAccount(blockchain, index?)

Returns a wallet account for a specific blockchain and index using BIP-44 derivation.

Parameters:

  • blockchain (string): The name of the blockchain (e.g., "ethereum")

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

Returns: Promise<IWalletAccountWithProtocols> - The wallet account with protocol support

Throws: Error if no wallet has been registered for the given blockchain

Example:

getAccountByPath(blockchain, path)

Returns a wallet account for a specific blockchain and BIP-44 derivation path.

Parameters:

  • blockchain (string): The name of the blockchain (e.g., "ethereum")

  • path (string): The derivation path (e.g., "0'/0/0")

Returns: Promise<IWalletAccountWithProtocols> - The wallet account with protocol support

Throws: Error if no wallet has been registered for the given blockchain

Example:

getFeeRates()

Returns current fee rates for all registered blockchains.

Returns: Promise<FeeRates> - The fee rates in base units

Example:

dispose()

Disposes all wallets and accounts, erasing any sensitive data from memory.

Example:

Static Methods

Method
Description
Returns

getRandomSeedPhrase()

Returns a random BIP-39 seed phrase

string

isValidSeedPhrase(seedPhrase)

Checks if a seed phrase is valid

boolean

getRandomSeedPhrase()

Returns a random BIP-39 seed phrase.

Returns: string - The seed phrase

Example:

isValidSeedPhrase(seedPhrase)

Checks if a seed phrase is valid according to BIP-39 standards.

Parameters:

  • seedPhrase (string): The seed phrase to validate

Returns: boolean - True if the seed phrase is valid

Example:

IWalletAccountWithProtocols

Extended wallet account interface that supports protocol registration and access. Extends IWalletAccount from @tetherto/wdk-wallet.

Methods

Method
Description
Returns
Throws

registerProtocol(label, protocol, config)

Registers a protocol for this specific account

IWalletAccountWithProtocols

-

getSwapProtocol(label)

Returns the swap protocol with the given label

ISwapProtocol

If protocol not found

getBridgeProtocol(label)

Returns the bridge protocol with the given label

IBridgeProtocol

If protocol not found

getLendingProtocol(label)

Returns the lending protocol with the given label

ILendingProtocol

If protocol not found

registerProtocol(label, protocol, config)

Registers a new protocol for this specific account.

Type Parameters:

  • P: typeof SwapProtocol | typeof BridgeProtocol | typeof LendingProtocol - A class that extends one of the @tetherto/wdk-wallet/protocol's classes

Parameters:

  • label (string): Unique label for the protocol (must be unique per account and protocol type)

  • protocol (P): The protocol class

  • config (ConstructorParameters

    [1]): The protocol configuration

Returns: IWalletAccountWithProtocols - The account instance (supports method chaining)

Example:

getSwapProtocol(label)

Returns the swap protocol with the given label.

Parameters:

  • label (string): The protocol label

Returns: ISwapProtocol - The swap protocol instance

Throws: Error if no swap protocol with the given label has been registered

Example:

getBridgeProtocol(label)

Returns the bridge protocol with the given label.

Parameters:

  • label (string): The protocol label

Returns: IBridgeProtocol - The bridge protocol instance

Throws: Error if no bridge protocol with the given label has been registered

Example:

getLendingProtocol(label)

Returns the lending protocol with the given label.

Parameters:

  • label (string): The protocol label

Returns: ILendingProtocol - The lending protocol instance

Throws: Error if no lending protocol with the given label has been registered

Example:

Complete Example

Types

FeeRates

Middleware Function

Protocol Types


Next Steps


Need Help?