Components
Batch Transaction
Several calls as one action. One wallet prompt with EIP-5792, step by step otherwise.
Approve-and-swap without two prompts. When the wallet supports atomic batches (EIP-5792), like Coinbase Smart Wallet and most smart accounts, every call goes out in one prompt and lands together. Other wallets get the same calls one by one, with a step list showing progress.
Connect the Demo Wallet. It acts like a smart account that supports batching.
- Approve 100 USDC
- Swap 100 USDC for ETH
Installation
Section titled “Installation”npx shadcn@latest add @0xui/batch-transactionpnpm dlx shadcn@latest add @0xui/batch-transactionyarn dlx shadcn@latest add @0xui/batch-transactionbunx --bun shadcn@latest add @0xui/batch-transactionimport { BatchTransaction } from "@/components/batch-transaction";
<BatchTransaction chainId={8453} calls={[ { label: "Approve USDC", to: usdc, data: encodeFunctionData({ abi: erc20Abi, functionName: "approve", args: [router, amount] }) }, { label: "Swap", to: router, data: swapData }, ]}> Approve and swap</BatchTransaction>;mode |
Behavior |
|---|---|
"auto" (default) |
Atomic if the wallet reports atomic support on the chain, otherwise sequential. |
"atomic" |
Always wallet_sendCalls. The wallet may reject it if it can’t batch. |
"sequential" |
One transaction per call, each waiting to be mined. Stops at the first revert or cancel. |
Sequential, for comparison:
- Approve 100 USDC
- Swap 100 USDC for ETH
Atomic batches are all-or-nothing: if one call reverts, none take effect. Sequential calls are not. A revert in step 2 leaves step 1 in place, so order your calls so that’s safe (approvals first).
States
Section titled “States”data-phase holds the current state, and data-atomic is set when batching. Phases: idle, switching, confirming, pending, success, reverted, cancelled, error. Sequential labels count steps: “Confirm 2 of 3 in wallet…”.
Headless: useBatchTransaction({ calls, chainId, mode }).
