WDK Core API Reference
Complete API documentation for @tetherto/wdk
Table of Contents
| Class | Description | Methods |
|---|---|---|
| WDK | Main class for managing wallets across multiple blockchains. Orchestrates wallet managers, protocols, middleware, and local transaction policies. | Constructor, Methods |
| IWalletAccount | Base writable wallet account interface from @tetherto/wdk-wallet. | Methods |
| IWalletAccountWithProtocols | Extended wallet account interface that supports protocol registration and access. Extends IWalletAccount. | Methods |
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
new WDK(seed)Parameters:
seed(string | Uint8Array): BIP-39 mnemonic seed phrase or seed bytes
Example:
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 | If a wallet is already registered for that blockchain |
registerProtocol(blockchain, label, protocol, config) | Registers a protocol globally for a blockchain | WDK | - |
registerMiddleware(blockchain, middleware) | Registers middleware for account decoration | WDK | - |
registerPolicy(policies, options?) | Registers local transaction policies for wallet account and protocol write methods | WDK | If policy configuration is invalid |
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(blockchain) | Returns current fee rates for a registered blockchain | Promise<FeeRates> | If wallet not registered |
dispose(blockchains?) | Disposes all registered wallets, or only the named blockchains, and clears their 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'sWalletManagerclass
Parameters:
blockchain(string): The name of the blockchain (e.g., "ethereum", "ton", "bitcoin")wallet(W): The wallet manager classconfig(ConstructorParameters<W>[1]): The configuration object for the wallet
Returns: WDK - The WDK instance (supports method chaining)
Throws: Error if a wallet is already registered for the same blockchain. Call dispose([blockchain]) before registering a replacement wallet for that blockchain.
Example:
import WDK from '@tetherto/wdk'
import WalletManagerEvm from '@tetherto/wdk-wallet-evm'
import WalletManagerTon from '@tetherto/wdk-wallet-ton'
const wdk = new WDK(seedPhrase)
// Register EVM wallet
wdk.registerWallet('ethereum', WalletManagerEvm, {
provider: 'https://eth.drpc.org'
})
// Register TON wallet
wdk.registerWallet('ton', WalletManagerTon, {
tonApiKey: 'YOUR_TON_API_KEY',
tonApiEndpoint: 'https://tonapi.io'
})
// Method chaining
const wdk2 = new WDK(seedPhrase)
.registerWallet('ethereum', WalletManagerEvm, ethereumWalletConfig)
.registerWallet('ton', WalletManagerTon, tonWalletConfig)registerProtocol(blockchain, label, protocol, config)
Registers a protocol globally for all accounts of a specific blockchain.
For swidge integrations, pass a concrete provider class that extends SwidgeProtocol from @tetherto/wdk-wallet/protocols.
Type Parameters:
P:typeof SwapProtocol | typeof BridgeProtocol | typeof LendingProtocol | typeof FiatProtocol | typeof SwidgeProtocol- A class that extends one of the@tetherto/wdk-wallet/protocolsclasses
Parameters:
blockchain(string): The name of the blockchainlabel(string): Unique label for the protocol (must be unique per blockchain and protocol type)protocol(P): The protocol classconfig(ConstructorParameters<P>[1]): The protocol configuration
Returns: WDK - The WDK instance (supports method chaining)
Example:
import veloraProtocolEvm from '@tetherto/wdk-protocol-swap-velora-evm'
import Usdt0ProtocolEvm from '@tetherto/wdk-protocol-bridge-usdt0-evm'
// Register swap protocol for Ethereum
wdk.registerProtocol('ethereum', 'velora', veloraProtocolEvm, {
apiKey: 'YOUR_velora_API_KEY'
})
// Register bridge protocol for Ethereum
wdk.registerProtocol('ethereum', 'usdt0', Usdt0ProtocolEvm)
// Register a concrete swidge provider for Ethereum
wdk.registerProtocol('ethereum', 'swidge', MySwidgeProtocol, swidgeProtocolConfig)
// Method chaining
const wdk2 = new WDK(seedPhrase)
.registerWallet('ethereum', WalletManagerEvm, ethereumWalletConfig)
.registerProtocol('ethereum', 'velora', veloraProtocolEvm, veloraProtocolConfig)registerMiddleware(blockchain, middleware)
Registers middleware for account decoration and enhanced functionality.
Parameters:
blockchain(string): The name of the blockchainmiddleware(<A extends IWalletAccount>(account: A) => Promise<A | void>): Middleware function called when deriving accounts
Returns: WDK - The WDK instance (supports method chaining)
Example:
// Simple logging middleware
wdk.registerMiddleware('ethereum', async (account) => {
console.log('New account:', await account.getAddress())
})
// Failover cascade middleware
import { getFailoverCascadeMiddleware } from '@tetherto/wdk-wrapper-failover-cascade'
wdk.registerMiddleware('ethereum', getFailoverCascadeMiddleware({
fallbackOptions: {
retries: 3,
delay: 1000
}
}))
// Method chaining
const wdk2 = new WDK(seedPhrase)
.registerWallet('ethereum', WalletManagerEvm, ethereumWalletConfig)
.registerMiddleware('ethereum', async (account) => {
console.log('New account:', await account.getAddress())
})registerPolicy(policies, options?)
Registers one or more local transaction policies on the WDK instance.
Policies are evaluated before wrapped account and protocol write methods execute. Matching DENY rules and governed-account default-deny outcomes throw PolicyViolationError; matching ALLOW rules permit the call only when no higher-priority DENY rule applies. Governed runtime accounts also expose account.simulate.<method>(...) mirrors so you can dry-run policy evaluation without sending, signing, or broadcasting.
For policy scoping, default-deny behavior, account-level overrides, and protocol simulation examples, see Transaction Policies.
Parameters:
policies(Policy | Policy[]): A single policy or an array of policies to register.options(RegisterPolicyOptions, optional): Engine-level settings.conditionTimeoutMsdefaults to30000milliseconds; the most recent value wins.
Returns: WDK - The WDK instance (supports method chaining)
Throws: PolicyConfigurationError if a policy or option fails validation, if an account-scoped policy omits its account binding, or if a policy references a wallet identifier that has not been registered.
Example:
import WDK, { PolicyViolationError } from '@tetherto/wdk'
const wdk = new WDK(seedPhrase)
.registerWallet('ethereum', WalletManagerEvm, ethereumWalletConfig)
.registerPolicy({
id: 'eth-send-limit',
name: 'ETH send limit',
scope: 'project',
wallet: 'ethereum',
rules: [
{
name: 'allow-normal-operations',
operation: '*',
action: 'ALLOW',
reason: 'Default local approval',
conditions: [() => true]
},
{
name: 'block-large-send',
operation: 'sendTransaction',
action: 'DENY',
reason: 'Transaction value exceeds local policy',
conditions: [
({ params }) => {
const value = (params as { value?: bigint } | null)?.value
return typeof value === 'bigint' && value > 1000000000000000000n
}
]
}
]
})
const account = await wdk.getAccount('ethereum', 0)
const simulation = await (account as any).simulate.sendTransaction({
to: '0x71C7656EC7ab88b098defB751B7401B5f6d8976F',
value: 2000000000000000000n
})
if (simulation.decision === 'DENY') {
console.warn(simulation.reason)
}
try {
await account.sendTransaction({
to: '0x71C7656EC7ab88b098defB751B7401B5f6d8976F',
value: 2000000000000000000n
})
} catch (error) {
if (error instanceof PolicyViolationError) {
console.error(error.reason)
}
}Supported PolicyOperation values are sendTransaction, signTransaction, transfer, approve, sign, signTypedData, signAuthorization, delegate, revokeDelegation, swap, bridge, supply, withdraw, borrow, repay, buy, sell, swidge, and *.
Use sign for message-style signing in this release. signMessage and signHash are not valid policy operation names.
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. When a registered policy targets the account, the returned runtime account is policy-enforced and exposes matching simulate helpers.
Throws: Error if no wallet has been registered for the given blockchain. Throws PolicyConfigurationError if a registered policy applies but the wallet account does not expose a read-only account view.
Example:
// Get first account (index 0)
const account = await wdk.getAccount('ethereum', 0)
// Get second account (index 1)
const account1 = await wdk.getAccount('ethereum', 1)
// Default index (0)
const defaultAccount = await wdk.getAccount('ethereum')
// This will throw an error if no wallet registered for 'tron'
try {
const tronAccount = await wdk.getAccount('tron', 0)
} catch (error) {
console.error('No wallet registered for tron blockchain')
}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. When a registered policy targets the account, the returned runtime account is policy-enforced and exposes matching simulate helpers.
Throws: Error if no wallet has been registered for the given blockchain. Throws PolicyConfigurationError if a registered policy applies but the wallet account does not expose a read-only account view.
Example:
// Full path: m/44'/60'/0'/0/1
const account = await wdk.getAccountByPath('ethereum', "0'/0/1")
// Different derivation path
const customAccount = await wdk.getAccountByPath('ton', "1'/2/3")getFeeRates(blockchain)
Returns current fee rates for a registered blockchain.
Parameters:
blockchain(string): The blockchain identifier passed toregisterWallet()
Returns: Promise<FeeRates> - The fee rates in base units
Throws: Error if no wallet has been registered for the given blockchain.
Example:
const feeRates = await wdk.getFeeRates('ethereum')
console.log('Fee rates:', feeRates)dispose(blockchains?)
Disposes all registered wallets when called without arguments, or only the wallets for the named blockchains when you pass a string array.
Parameters:
blockchains(string[], optional): The blockchain identifiers to dispose. Omit this parameter to dispose every registered wallet.
Example:
// Clean up all sensitive data
wdk.dispose()
// Dispose only one registered wallet
wdk.dispose(['ethereum'])Static Methods
| Method | Description | Returns |
|---|---|---|
getRandomSeedPhrase(wordCount?) | Returns a random BIP-39 seed phrase (12 or 24 words) | string |
isValidSeed(seed) | Checks if a seed phrase or seed bytes value is valid | boolean |
getRandomSeedPhrase(wordCount?)
Returns a random BIP-39 seed phrase. Supports both 12-word (128-bit entropy) and 24-word (256-bit entropy) seed phrases.
Parameters:
wordCount(12 | 24, optional): The number of words in the seed phrase. Defaults to 12.
Returns: string - The seed phrase
Example:
// Generate 12-word seed phrase (default)
const seedPhrase12 = WDK.getRandomSeedPhrase()
console.log('Generated 12-word seed:', seedPhrase12)
// Output: "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
// Generate 24-word seed phrase (higher security)
const seedPhrase24 = WDK.getRandomSeedPhrase(24)
console.log('Generated 24-word seed:', seedPhrase24)
// Output: "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art"isValidSeed(seed)
Checks if a seed phrase or seed bytes value is valid.
Parameters:
seed(string | Uint8Array): The seed phrase or seed bytes to validate
Returns: boolean - True if the seed is valid
Example:
const isValid = WDK.isValidSeed('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about')
console.log('Seed phrase valid:', isValid) // true
const isInvalid = WDK.isValidSeed('invalid seed phrase')
console.log('Seed phrase valid:', isInvalid) // falseIWalletAccount
Base writable wallet account interface exposed by @tetherto/wdk-wallet. Blockchain modules implement this interface and may narrow the transaction type accepted by signTransaction() and sendTransaction().
Methods
| Method | Description | Returns | Throws |
|---|---|---|---|
getAddress() | Returns the account address | Promise<string> | - |
sign(message) | Signs a message with the account private key | Promise<string> | - |
signTransaction(tx) | Signs a transaction without broadcasting it | Promise<unknown> | If the transaction is invalid for the module |
verify(message, signature) | Verifies a message signature | Promise<boolean> | - |
sendTransaction(tx) | Signs, broadcasts, and returns the transaction result | Promise<TransactionResult> | If provider access or broadcast fails |
transfer(options) | Transfers a token where supported by the module | Promise<TransferResult> | If the module does not support token transfers |
toReadOnlyAccount() | Returns a read-only account copy | Promise<IWalletAccountReadOnly> | - |
dispose() | Clears sensitive account material from memory | void | - |
signTransaction(tx)
Signs a transaction with the account private key and returns the signed transaction payload without broadcasting it. Use this when your app needs offline signing, external transaction submission, or a separate review step before broadcast.
Parameters:
tx(Transaction): Module-specific transaction object. For example, EVM accounts acceptEvmTransaction, and Bitcoin accounts acceptBtcTransaction.
Returns: Promise<unknown> - The signed transaction payload. Wallet modules may narrow this return type, such as a hex string for EVM and Bitcoin transactions.
Example:
const account = await wdk.getAccount('ethereum', 0)
const signedTransaction = await account.signTransaction({
to: '0x71C7656EC7ab88b098defB751B7401B5f6d8976F',
value: 1000000000000000n
})
console.log('Signed transaction:', signedTransaction)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 |
getFiatProtocol(label) | Returns the fiat protocol with the given label | IFiatProtocol | If protocol not found |
getSwidgeProtocol(label) | Returns the swidge protocol with the given label | ISwidgeProtocol | 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 | typeof FiatProtocol | typeof SwidgeProtocol- A class that extends one of the@tetherto/wdk-wallet/protocolsclasses
Parameters:
label(string): Unique label for the protocol (must be unique per account and protocol type)protocol(P): The protocol classconfig(ConstructorParameters<P>[1]): The protocol configuration
Returns: IWalletAccountWithProtocols - The account instance (supports method chaining)
Example:
import Usdt0ProtocolEvm from '@tetherto/wdk-protocol-bridge-usdt0-evm'
const account = await wdk.getAccount('ethereum', 0)
// Register protocol for this specific account
account.registerProtocol('usdt0', Usdt0ProtocolEvm, {
apiKey: 'YOUR_API_KEY'
})
// Method chaining
const account2 = await wdk.getAccount('ethereum', 1)
.registerProtocol('usdt0', Usdt0ProtocolEvm, usdt0ProtocolConfig)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:
import veloraProtocolEvm from '@tetherto/wdk-protocol-swap-velora-evm'
// Register swap protocol
account.registerProtocol('velora', veloraProtocolEvm, veloraProtocolConfig)
// Get swap protocol
const velora = account.getSwapProtocol('velora')
// Use the protocol
const swapResult = await velora.swap({
tokenIn: '0x...',
tokenOut: '0x...',
tokenInAmount: 1000000n
})
// This will throw an error
// try {
// const uniswap = account.getSwapProtocol('uniswap')
// } catch (error) {
// console.error('No swap protocol with label "uniswap" found')
// }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:
import Usdt0ProtocolEvm from '@tetherto/wdk-protocol-bridge-usdt0-evm'
// Register bridge protocol
account.registerProtocol('usdt0', Usdt0ProtocolEvm)
// Get bridge protocol
const usdt0 = account.getBridgeProtocol('usdt0')
// Use the protocol
await account.approve({
token: '0x...',
spender: '0x...', // OFT or bridge spender address
amount: 1000000n
})
const bridgeResult = await usdt0.bridge({
targetChain: 'arbitrum',
recipient: '0x...',
token: '0x...',
amount: 1000000n,
oftContractAddress: '0x...' // Same address used as approval spender
})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:
import AaveProtocolEvm from '@tetherto/wdk-protocol-lending-aave-evm'
// Register lending protocol
account.registerProtocol('aave', AaveProtocolEvm, aaveProtocolConfig)
// Get lending protocol
const aave = account.getLendingProtocol('aave')
// Use the protocol
const supplyResult = await aave.supply({
token: '0x...',
amount: 1000000n
})getFiatProtocol(label)
Returns the fiat protocol with the given label.
Parameters:
label(string): The protocol label
Returns: IFiatProtocol - The fiat protocol instance
Throws: Error if no fiat protocol with the given label has been registered
Example:
import MoonPayProtocol from '@tetherto/wdk-protocol-fiat-moonpay'
// Register fiat protocol
account.registerProtocol('moonpay', MoonPayProtocol, moonpayProtocolConfig)
// Get fiat protocol
const moonpay = account.getFiatProtocol('moonpay')
const buyUrl = await moonpay.buy({
cryptoAsset: 'usdt',
fiatCurrency: 'usd',
fiatAmount: 10000n
})getSwidgeProtocol(label)
Returns the swidge protocol with the given label.
The examples below use MySwidgeProtocol as the concrete provider class supplied by your swidge provider module.
Parameters:
label(string): The protocol label
Returns: ISwidgeProtocol - The swidge protocol instance
Throws: Error if no swidge protocol with the given label has been registered
Example:
// Register a concrete provider class that extends SwidgeProtocol
account.registerProtocol('swidge', MySwidgeProtocol, swidgeProtocolConfig)
// Get swidge protocol
const swidge = account.getSwidgeProtocol('swidge')
const quote = await swidge.quoteSwidge({
fromToken: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
toToken: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9',
toChain: 'arbitrum',
fromTokenAmount: 1000000n
})Complete Example
import WDK from '@tetherto/wdk'
import WalletManagerEvm from '@tetherto/wdk-wallet-evm'
import WalletManagerTon from '@tetherto/wdk-wallet-ton'
import veloraProtocolEvm from '@tetherto/wdk-protocol-swap-velora-evm'
import Usdt0ProtocolEvm from '@tetherto/wdk-protocol-bridge-usdt0-evm'
// Initialize WDK Manager
const wdk = new WDK(seedPhrase)
.registerWallet('ethereum', WalletManagerEvm, {
provider: 'https://eth.drpc.org'
})
.registerWallet('ton', WalletManagerTon, {
tonApiKey: 'YOUR_TON_API_KEY',
tonApiEndpoint: 'https://tonapi.io'
})
.registerProtocol('ethereum', 'velora', veloraProtocolEvm, {
apiKey: 'YOUR_velora_API_KEY'
})
.registerProtocol('ethereum', 'usdt0', Usdt0ProtocolEvm)
// Get accounts
const accountEth = await wdk.getAccount('ethereum', 3)
const accountTon = await wdk.getAccountByPath('ton', "1'/2/3")
// Use wallet account methods
const { hash, fee } = await accountEth.sendTransaction({
to: '0x...',
value: 1000000000000000000n // 1 ETH
})
// Use protocols
const velora = accountEth.getSwapProtocol('velora')
const swapResult = await velora.swap(swapOptions)
const usdt0 = accountEth.getBridgeProtocol('usdt0')
// bridgeOptions.oftContractAddress is the source-chain bridge spender.
await accountEth.approve({
token: bridgeOptions.token,
spender: bridgeOptions.oftContractAddress,
amount: bridgeOptions.amount
})
const bridgeResult = await usdt0.bridge(bridgeOptions)
// Clean up
wdk.dispose()Types
FeeRates
interface FeeRates {
[blockchain: string]: {
normal: number;
fast: number;
};
}Middleware Function
type MiddlewareFunction = <A extends IWalletAccount>(
account: A
) => Promise<A | void>;Policy Types
type PolicyAction = 'ALLOW' | 'DENY'
type PolicyScope = 'project' | 'account'
type PolicyOperation =
| 'sendTransaction'
| 'signTransaction'
| 'transfer'
| 'approve'
| 'sign'
| 'signTypedData'
| 'signAuthorization'
| 'delegate'
| 'revokeDelegation'
| 'swap'
| 'bridge'
| 'supply'
| 'withdraw'
| 'borrow'
| 'repay'
| 'buy'
| 'sell'
| 'swidge'
| '*'
type PolicyCondition = (context: PolicyContext) => boolean | Promise<boolean>
interface PolicyContext {
operation: PolicyOperation
wallet: string
account: IWalletAccountReadOnly
params: unknown
args: readonly unknown[]
}
interface PolicyRule {
name: string
operation: PolicyOperation | PolicyOperation[]
action: PolicyAction
conditions: PolicyCondition[]
reason?: string
override_broader_scope?: boolean
}
interface Policy {
id: string
name: string
scope: PolicyScope
wallet?: string | string[]
accounts?: Array<string | number>
rules: PolicyRule[]
}
interface RegisterPolicyOptions {
conditionTimeoutMs?: number
}scope: 'project' can apply across all registered wallets or only the wallets named in wallet. scope: 'account' requires both wallet and accounts; account entries can be a derivation path string or an account index number.
Simulation results returned by the runtime account.simulate.<method>(...) mirrors include decision, policy_id, matched_rule, reason, and a trace array that records evaluated rules.
Protocol Types
// Swap Protocol
interface ISwapProtocol {
swap(options: SwapOptions): Promise<SwapResult>;
}
// Bridge Protocol
interface IBridgeProtocol {
bridge(options: BridgeOptions): Promise<BridgeResult>;
}
// Lending Protocol
interface ILendingProtocol {
supply(options: LendingOptions): Promise<LendingResult>;
withdraw(options: LendingOptions): Promise<LendingResult>;
borrow(options: LendingOptions): Promise<LendingResult>;
repay(options: LendingOptions): Promise<LendingResult>;
}
// Swidge Protocol (unified swap + bridge + route)
interface ISwidgeProtocol extends ISwapProtocol, IBridgeProtocol {
quoteSwidge(options: SwidgeOptions): Promise<SwidgeQuote>;
swidge(options: SwidgeOptions, config?: SwidgeProtocolConfig): Promise<SwidgeResult>;
getSwidgeStatus(id: string, options?: SwidgeStatusOptions): Promise<SwidgeStatusResult>;
getSupportedChains(): Promise<SwidgeSupportedChain[]>;
getSupportedTokens(options?: SwidgeSupportedTokensOptions): Promise<SwidgeSupportedToken[]>;
}Swidge Protocol
SwidgeProtocol is an abstract base class exported from @tetherto/wdk-wallet/protocols for provider packages that implement a single, route-aware surface for same-chain swaps and cross-chain bridges. It implements ISwidgeProtocol, which extends both ISwapProtocol and IBridgeProtocol, so the base class derives swap(), quoteSwap(), bridge(), and quoteBridge() by delegating to swidge() and quoteSwidge(). Provider subclasses implement the abstract methods below.
| Method | Description | Returns |
|---|---|---|
quoteSwidge(options) | Returns a non-binding quote for a swap/bridge operation | Promise<SwidgeQuote> |
swidge(options, config?) | Executes a swap/bridge operation | Promise<SwidgeResult> |
getSwidgeStatus(id, options?) | Returns the current status of an in-flight operation | Promise<SwidgeStatusResult> |
getSupportedChains() | Returns the chains the provider supports | Promise<SwidgeSupportedChain[]> |
getSupportedTokens(options?) | Returns the tokens the provider supports, optionally route-scoped | Promise<SwidgeSupportedToken[]> |
The SwidgeOptions input combines common fields (fromToken, toToken, optional toChain, recipient, refundAddress, slippage) with either an exact-in (fromTokenAmount) or exact-out (toTokenAmount) amount. The optional SwidgeProtocolConfig accepts maxNetworkFeeBps and maxProtocolFeeBps to cap acceptable fees.
See the Swidge Protocol Interface page for the full discovery, quote, execution, status, fee, and result shapes.
type SwidgeProtocolConfig = {
maxNetworkFeeBps?: number | bigint;
maxProtocolFeeBps?: number | bigint;
};
type SwidgeOptions = {
fromToken: string;
toToken: string;
toChain?: string | number; // defaults to the source chain (same-chain swap)
recipient?: string;
refundAddress?: string;
slippage?: number; // decimal, e.g. 0.01 for 1%
} & (
| { fromTokenAmount: number | bigint } // exact-in
| { toTokenAmount: number | bigint } // exact-out
);
type SwidgeStatus =
| 'pending' | 'action-required' | 'completed' | 'failed'
| 'refund-pending' | 'refunded' | 'cancelled' | 'expired' | 'partial';Next Steps
WDK Core Configuration
Get started with WDK's configuration
WDK Core Usage
Get started with WDK's Usage
Wallet Modules
Explore blockchain-specific wallet modules
Bridge Modules
Cross-chain USD₮0 bridges