Batch Transactions
Demo
Introduction
One great advantage of smart contract wallets is the ability to execute transactions in batches. That is, you can execute multiple transactions as if it's a single transaction, so you get to save on confirmation time and gas costs. It's also safer because these transactions either all execute or all revert, no in-between, which is a property known as "atomicity."
API
Ethers
// signer is a ZeroDevSigner
// This will mint two NFTs at a time
await signer.execBatch([
{
to: nftAddress,
data: nftContract.interface.encodeFunctionData("mint", [address]),
},
{
to: nftAddress,
data: nftContract.interface.encodeFunctionData("mint", [address]),
},
])
Each object in the array for execBatch
can have three keys:
to
: the contract you are interacting withdata
: the calldatavalue
: the value of the transaction
Wagmi
import { usePrepareContractBatchWrite, useContractBatchWrite, useWaitForAATransaction } from "@zerodevapp/wagmi";
Full Code (Editable)
Result
Loading...