WDK logoWDK documentation

Integrate Protocols

Learn how to use Swidge, Swap, Bridge, and Lending protocols.

The WDK Core module supports registering external protocols. This allows you to extend the basic wallet functionality with advanced features like swidge routes, token swapping, cross-chain bridging, and lending.

Register Protocols

You can register protocols globally (for all new accounts).

Global registration ensures that every account you retrieve already has the protocol ready to use. You can do this by chaining a call to .registerProtocol() on the WDK instance.

1. Install Protocol Modules

Install the @tetherto/wdk-protocol-swap-velora-evm and @tetherto/wdk-protocol-bridge-usdt0-evm packages:

npm install @tetherto/wdk-protocol-swap-velora-evm && npm install @tetherto/wdk-protocol-bridge-usdt0-evm

2. Register in Code

Now, import the protocol modules and register them with your WDK instance. This makes the protocol methods available to any account derived from that instance.

First, import the necessary modules:

Import Protocols
import veloraProtocolEvm from '@tetherto/wdk-protocol-swap-velora-evm'
import usdt0ProtocolEvm from '@tetherto/wdk-protocol-bridge-usdt0-evm'

Then, register the protocols for the specific chains they support:

Register Protocols
// Register protocols for specific chains
const wdk = new WDK(seedPhrase)
  .registerWallet('ethereum', WalletManagerEvm, ethConfig)

  // Register Velora Swap for Ethereum
  .registerProtocol('ethereum', 'velora', veloraProtocolEvm, {
    apiKey: 'YOUR_API_KEY'
  })

  // Register USDT0 Bridge for Ethereum
  .registerProtocol('ethereum', 'usdt0', usdt0ProtocolEvm, {
     ethereumRpcUrl: 'https://eth.drpc.org' // Configuration depends on the module
  })

Use Protocols

Once registered, you can access the protocol instance using the specific getter methods, such as getSwapProtocol, getBridgeProtocol, getLendingProtocol, or getFiatProtocol.

Swidge Routes

Use a swidge provider module for new swap, bridge, or combined route integrations. The shared swidge interface discovers supported chains and tokens with getSupportedChains() and getSupportedTokens(), quotes with quoteSwidge(), executes with swidge(), and tracks asynchronous settlement with getSwidgeStatus(). The provider can decide whether the route is fulfilled as a same-chain swap, same-token bridge, combined route, intent, solver route, or aggregator route. The example below assumes swidge is an instance of a concrete provider module that implements the shared interface.

Swidge route flow
const chains = await swidge.getSupportedChains()
const tokens = await swidge.getSupportedTokens({
  fromChain: 'ethereum',
  toChain: 'arbitrum'
})

const options = {
  fromToken: '0xSourceToken...',
  toToken: '0xDestinationToken...',
  toChain: 'arbitrum',
  recipient: '0xRecipient...',
  fromTokenAmount: 1000000n,
  slippage: 0.01
}

const quote = await swidge.quoteSwidge(options)

const result = await swidge.swidge(options, {
  maxNetworkFeeBps: 50,
  maxProtocolFeeBps: 25
})

const status = await swidge.getSwidgeStatus(result.id, {
  toChain: 'arbitrum'
})

Use discovery results to build token and chain selectors, but continue to show the quote details before execution. swidge() is the write step in the shared swidge flow.

Existing swap and bridge modules keep their current accessors for released modules. Prefer the swidge protocol interface for new protocol integrations because the standalone swap and bridge interfaces are expected to be deprecated after swidge provider coverage is available.

Swapping Tokens

Use getSwapProtocol to access registered swap services on any wallet account.

Swap Tokens
const ethAccount = await wdk.getAccount('ethereum', 0)
const velora = ethAccount.getSwapProtocol('velora')

const result = await velora.swap({
  tokenIn: '0x...', // Address of token to sell
  tokenOut: '0x...', // Address of token to buy
  tokenInAmount: 1000000n // Amount to swap
})

Bridging Assets

  1. Use getBridgeProtocol to access cross-chain bridges.
  2. Approve the source-chain bridge spender for the token and amount.
  3. Call bridge from the bridge protocol to send tokens from one protocol to another.
Bridge Assets
const ethAccount = await wdk.getAccount('ethereum', 0)
const usdt0 = ethAccount.getBridgeProtocol('usdt0')

await ethAccount.approve({
  token: '0x...', // ERC20 Token Address
  spender: '0x...', // OFT or bridge spender address
  amount: 1000000n
})

const result = await usdt0.bridge({
  targetChain: 'ton',
  recipient: 'UQBla...', // TON address
  token: '0x...', // ERC20 Token Address
  amount: 1000000n,
  oftContractAddress: '0x...' // Same address used as approval spender
})

Protocol Availability: If you try to access a protocol that hasn't been registered (e.g., getSwapProtocol('uniswap')), the SDK will throw an error. always ensure registration matches the ID you request.

Next Steps

Learn how to configure middleware to add logging or failover protection to your wallet interactions.

On this page