Embedded wallets vs EOA wallets
- EOA wallets (MetaMask, Phantom, Coinbase Wallet, etc.) are injected into the page and expose a public address as soon as they connect. The SDK can discover them on its own with auto-detection.
- Embedded wallets are created or connected after the user logs in. No address exists at app boot, and the SDK cannot discover them. Your app must resolve the wallet from the embedded wallet provider and pass it to Trustware explicitly.
Adapt the embedded wallet
useEIP1193 from @trustware/sdk/wallet adapts any EIP-1193 provider into the WalletInterFaceAPI that TrustwareProvider accepts. The pattern is always the same three steps: resolve the embedded wallet, get its EIP-1193 provider, and wrap it.
This example uses Privy, but any embedded wallet provider that exposes an EIP-1193 provider works the same way:
Swap with an embedded wallet
In this flow the embedded wallet is the host wallet: it signs the swap and receives the output. Enable swap mode infeatures, pass the adapted wallet through the wallet prop, and set autoDetect={false} so the SDK does not run its own wallet discovery alongside it.
autoDetect={false} is required whenever you pass a wallet prop.
Deposit into an embedded wallet
In this flow the embedded wallet is only the destination. The payer is an EOA the user connects inside the widget, so leave auto-detection on. Because the embedded wallet address does not exist until after login, set it at runtime withTrustware.setDestinationAddress() once the provider is ready:
routes.toAddress in config covers the case where the address is already known at mount; the runtime setter covers wallets provisioned after mount. See runtime destination for the full setter reference.
Refresh balances after a deposit
If your app displays the embedded wallet balance, refresh it when a deposit lands. BothonSuccess and the transaction_success event work; the example below uses both so the balance updates as soon as the transaction succeeds and again when settlement completes.
Next: withdrawals
There is no prebuilt widget for moving funds back out of an embedded wallet. Withdrawals use the headless core with the embedded wallet as the source.Embedded wallet withdrawals
Build and send a withdrawal route from an embedded wallet with getBalances, buildRoute, useWallet, sendRouteTransaction, and submitReceipt.
