Trustware.getBalances()to load what the wallet can sendTrustware.buildRoute()to get a signable routeTrustware.useWallet()to attach the embedded walletTrustware.sendRouteTransaction()to sign and broadcastTrustware.submitReceipt()to confirm the transaction and enable status tracking
This guide covers users withdrawing funds held in an embedded wallet your app provisioned. It is unrelated to paymaster fund management in the Client Dashboard.
When to use this pattern
Choose this pattern when:- your app provisions embedded wallets and users hold balances in them
- users need to move those funds to an external wallet or another chain
- you want to build the withdrawal UI in your own design system
Prerequisites
- An adapted embedded wallet. Follow use Trustware with embedded wallets to wrap the wallet’s EIP-1193 provider with
useEIP1193. - An initialized SDK. Either mount
TrustwareProviderwith your config, or callTrustware.init(config)before the calls below.
routes is required at init in deposit mode, which is the default, so supply
a destination even for a withdrawal flow. Each buildRoute call below passes
its own chains, tokens, and addresses, and those take precedence over these
config defaults.1. Load embedded wallet balances
getBalances returns the token balances for an address on one chain. Filter to funded rows to drive your source-token picker:
getBalances results per chain and address. Pass forceRefresh: true to force a fresh on-chain scan, for example right after a deposit lands; omit it to reuse the cache when the user is only switching between chains.
Each row is a BalanceRow:
2. Build the withdrawal route
Build a route with the embedded wallet asfromAddress and the user’s chosen destination as toAddress:
fromAmount is in the token’s smallest unit. Convert human-readable input with the token’s decimals before calling the SDK, for example with viem’s parseUnits. See headless core for the full BuildRouteBody and BuildRouteResult shapes.
3. Attach the embedded wallet and send
Attach the adapted wallet, then sign and broadcast the route.sendRouteTransaction switches the wallet to the route’s chain if needed, grants any ERC-20 allowance the route requires, and returns the transaction hash:
sendRouteTransaction reads the current allowance, requests an approval for the exact amount when one is missing, waits for it to confirm, and only then requests the route signature. Surface that in your UI so the second prompt is not a surprise.
4. Submit the receipt and track status
Submit the transaction hash so Trustware can track settlement, then poll until the route resolves:pollStatus resolves when the route reaches success, when it reaches failed, and when polling times out, so always check result.status rather than treating a resolved promise as success. Use Trustware.getStatus(route.intentId) instead if you want to poll on your own schedule.
