Configure Middleware
Learn how to intercept and enhance wallet operations with middleware.
Middleware allows you to intercept wallet operations. You can use this to add logging, implement retry logic, or route provider failover to the supported failover provider.
Register Middleware
When registering middleware, you should reference a specific chain. The middleware function runs every time an account is instantiated or an operation is performed, depending on the implementation.
Logging
This simple middleware logs a message whenever a new account is accessed.
wdk.registerMiddleware('ethereum', async (account) => {
const address = await account.getAddress()
console.log('Accessed Ethereum account:', address)
// You can also attach custom properties or wrap methods here
})Use provider failover
Provider failover is handled outside core middleware. Use the current @tetherto/wdk-failover-provider package when you need provider-level retry and fallback across RPC endpoints.
Install the failover provider package:
npm install @tetherto/wdk-failover-providerImport the provider in your wallet or infrastructure setup:
import FailoverProvider from '@tetherto/wdk-failover-provider'Use this when your app depends on external RPC providers and needs a backup route if the primary provider is slow or unavailable.
See Add provider failover, failover configuration, and the failover API reference for the supported setup.
Next Steps
Learn about error handling and best practices to ensure your application is robust and secure.