Batch transactions
Smart Wallet enables you to send multiple onchain calls in a single transaction, improving UX by reducing multi-step interactions to a single click. A common example is combining an ERC-20 approve
with a swap operation.
You can submit batch transactions using the new wallet_sendCalls
RPC method.
Check wallet compatibility for atomic batching
- First, verify if your app supports atomic batching (This step is crucial if your app supports multiple wallet types)
- Use the
useCapabilities
hook from Wagmi experimental features
- Implement fallback functionality for unsupported wallets
Note: The useWriteContracts
and useCapabilities
hooks rely on new wallet RPC and may not be supported in all wallets.
_26import { useCapabilities } from 'wagmi/experimental'
_26 const { data: capabilities } = useCapabilities()
_26 // Returns capability object per chain:
_26 // Check if atomic batching is supported
_26 const isAtomicBatchSupported = capabilities?.[84532]?.atomicBatch?.supported
_26 {isAtomicBatchSupported ? (
_26 <BatchTransactionComponent />
_26 <FallbackComponent />
Set up contract interactions
- Import required hooks:
useAccount
and useWriteContracts
from Wagmi
- Define your smart contract ABI
- Initialize the
useWriteContracts
hook for batch transactions
- Create a transaction handling function that can process multiple contract calls
Important: Make sure your contract ABIs are correctly typed for better development experience.
_47import { useAccount } from 'wagmi'
_47import { useWriteContracts } from 'wagmi/experimental'
_47// Define your contract ABI
_47 stateMutability: 'nonpayable',
_47 inputs: [{ name: 'to', type: 'address' }],
_47function BatchTransactionComponent() {
_47 const account = useAccount()
_47 const { writeContracts } = useWriteContracts()
_47 const handleBatchTransaction = () => {
_47 address: "0x119Ea671030FBf79AB93b436D2E20af6ea469a19",
_47 functionName: "safeMint",
_47 args: [account.address],
_47 // Add more contract interactions as needed
_47 address: "0x119Ea671030FBf79AB93b436D2E20af6ea469a19",
_47 functionName: "safeMint",
_47 args: [account.address],
_47 onClick={handleBatchTransaction}
_47 className="px-4 py-2 bg-blue-600 text-white rounded"
_47 Execute Batch Transaction
Implement transaction status monitoring
- Add the
useCallsStatus
hook to track transaction status
- Configure polling interval for status updates
- Display transaction status to users
- Handle transaction completion and errors
Pro tip: The polling interval can be adjusted based on your needs, but 1 second is a good default.
_57import { useCallsStatus } from 'wagmi/experimental'
_57function BatchTransactionComponent() {
_57 const { data: id, writeContracts } = useWriteContracts()
_57 const { data: callsStatus } = useCallsStatus({
_57 // Poll every second until confirmed
_57 refetchInterval: (data) =>
_57 data.state.data?.status === "CONFIRMED" ? false : 1000,
_57 // Example response structure:
_57 // status: 'CONFIRMED',
_57 // topics: ['0x...'],
_57 // status: 'success',
_57 // blockHash: '0x...',
_57 // blockNumber: 122414523n,
_57 // transactionHash: '0x...'
_57 <div className="space-y-4">
_57 onClick={handleBatchTransaction}
_57 className="px-4 py-2 bg-blue-600 text-white rounded"
_57 Execute Batch Transaction
_57 <div className="p-4 border rounded">
_57 <p className="font-semibold">
_57 Status: {callsStatus.status}
_57 {callsStatus.status === 'CONFIRMED' && (
_57 <p className="text-green-600">
_57 Transaction confirmed! Hash: {callsStatus.receipts[0].transactionHash}