When to use this pattern
Choose this pattern when:- your app has an existing Wagmi or RainbowKit setup
- you have custom wallet orchestration and do not want the SDK to interfere
- you want the full widget flow but need Trustware to use your connected wallet
Setup
Import the Wagmi adapter
The
useWagmi adapter is exported from a separate sub-path to keep the main bundle lean. It converts a viem WalletClient into the wallet interface that TrustwareProvider expects.Create a stable wallet reference with useMemo
useWalletClient returns a new object reference on every render. Wrap the adapter in useMemo so the wallet reference only changes when walletClient itself changes.How it works
What useWagmi does
useWagmi adapts a viem WalletClient to the WalletInterFaceAPI that TrustwareProvider accepts. It exposes the address, chain, and signing methods Trustware needs to build and submit routes, without requiring you to implement that bridge yourself.
autoDetect={false}
Setting autoDetect={false} tells TrustwareProvider not to run its own wallet discovery. Without this, the SDK would attempt auto-detection even when a wallet is already provided, which can cause conflicts with your existing wallet state.
Why useMemo matters
useWalletClient from Wagmi returns a new object reference on every render cycle, even when the underlying wallet hasn’t changed. Without useMemo, every render would produce a new wallet value, causing TrustwareProvider to treat each one as a wallet change and unnecessarily re-initialize its internal state.
Using with RainbowKit
TrustwareProvider must sit inside your Wagmi and RainbowKit providers so it has access to their React context. If you place it outside WagmiProvider, calls to useWalletClient will fail.
Using with embedded wallets
The same pattern works for embedded wallets your app provisions, for example through Privy. UseuseEIP1193 from @trustware/sdk/wallet to adapt any EIP-1193 provider, including an embedded wallet’s provider, into the wallet interface TrustwareProvider accepts. As with every host wallet, pass it through the wallet prop and set autoDetect={false}.
See use Trustware with embedded wallets for the full pattern, including how to resolve the embedded wallet safely and run swaps and deposits against it.