Integrate Protocols
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 (Recommended)
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-evm2. 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 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 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.
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
- Use
getBridgeProtocolto access cross-chain bridges. - Call
bridgefrom the bridge protocol to send tokens from one protocol to another.
const ethAccount = await wdk.getAccount('ethereum', 0)
const usdt0 = ethAccount.getBridgeProtocol('usdt0')
const result = await usdt0.bridge({
targetChain: 'ton',
recipient: 'UQBla...', // TON address
token: '0x...', // ERC20 Token Address
amount: 1000000n
})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.