githubEdit

Protocol Integration

Learn how to use Swaps, Bridges, and Lending protocols.

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

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-evmarrow-up-right and @tetherto/wdk-protocol-bridge-usdt0-evmarrow-up-right 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: getSwapProtocol, getBridgeProtocol, or getLendingProtocol.

Swapping Tokens

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

Bridging Assets

  1. Use getBridgeProtocol to access cross-chain bridges.

  2. Call bridge from the bridge protocol to send tokens from one protocol to another.

circle-info

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.