Send batch transactions
Using Smart Wallets, you can batch multiple actions (such as token transfers, approvals, or swaps) into a single transaction. Users will no longer need multiple confirmations or pop-ups to handle sequential actions. This helps you speed up how users interact with your app and improve the user experience.
How it works
Smart wallets support running a batch of actions, called “calls”, in a single transaction. These actions are atomic, which means if any of them fail (revert), the entire batched transaction will revert. This protects users from accidentally having part of a batch apply, but not all.
To use this feature, you just need to specify multiple calls to make. The parameter type accepts an array of calls, and each element should contain the action you want the wallet to take.
Prerequisites
- API key from your dashboard
- Smart Wallets installed and configured in your project.
Implementation
React
JavaScript
API
Use the useSendCalls
hook to send a batched transaction. You can also use the usePrepareCalls
hook to only prepare the transaction for signing.
export const const swapAbi: readonly [{
readonly type: "constructor";
readonly inputs: readonly [];
readonly stateMutability: "nonpayable";
}, {
readonly type: "function";
readonly name: "mint";
readonly inputs: readonly [{
readonly name: "amount1";
readonly type: "uint256";
readonly internalType: "uint256";
}, {
readonly name: "amount2";
readonly type: "uint256";
readonly internalType: "uint256";
}];
readonly outputs: readonly [];
readonly stateMutability: "nonpayable";
}, {
readonly type: "function";
readonly name: "swapUSDCtoWETH";
readonly inputs: readonly [{
readonly name: "amountIn";
readonly type: "uint256";
readonly internalType: "uint256";
}, {
...;
}];
readonly outputs: readonly [];
readonly stateMutability: "nonpayable";
}, {
...;
}, {
...;
}, {
...;
}]swapAbi = [
{
type: "constructor"type: "constructor",
inputs: readonly []inputs: [],
stateMutability: "nonpayable"stateMutability: "nonpayable",
},
{
type: "function"type: "function",
name: "mint"name: "mint",
inputs: readonly [{
readonly name: "amount1";
readonly type: "uint256";
readonly internalType: "uint256";
}, {
readonly name: "amount2";
readonly type: "uint256";
readonly internalType: "uint256";
}]inputs: [
{
name: "amount1"name: "amount1",
type: "uint256"type: "uint256",
internalType: "uint256"internalType: "uint256",
},
{
name: "amount2"name: "amount2",
type: "uint256"type: "uint256",
internalType: "uint256"internalType: "uint256",
},
],
outputs: readonly []outputs: [],
stateMutability: "nonpayable"stateMutability: "nonpayable",
},
{
type: "function"type: "function",
name: "swapUSDCtoWETH"name: "swapUSDCtoWETH",
inputs: readonly [{
readonly name: "amountIn";
readonly type: "uint256";
readonly internalType: "uint256";
}, {
readonly name: "amountOut";
readonly type: "uint256";
readonly internalType: "uint256";
}]inputs: [
{
name: "amountIn"name: "amountIn",
type: "uint256"type: "uint256",
internalType: "uint256"internalType: "uint256",
},
{
name: "amountOut"name: "amountOut",
type: "uint256"type: "uint256",
internalType: "uint256"internalType: "uint256",
},
],
outputs: readonly []outputs: [],
stateMutability: "nonpayable"stateMutability: "nonpayable",
},
{
type: "function"type: "function",
name: "swapWETHtoUSDC"name: "swapWETHtoUSDC",
inputs: readonly [{
readonly name: "amountIn";
readonly type: "uint256";
readonly internalType: "uint256";
}, {
readonly name: "amountOut";
readonly type: "uint256";
readonly internalType: "uint256";
}]inputs: [
{
name: "amountIn"name: "amountIn",
type: "uint256"type: "uint256",
internalType: "uint256"internalType: "uint256",
},
{
name: "amountOut"name: "amountOut",
type: "uint256"type: "uint256",
internalType: "uint256"internalType: "uint256",
},
],
outputs: readonly []outputs: [],
stateMutability: "nonpayable"stateMutability: "nonpayable",
},
{
type: "function"type: "function",
name: "usdc"name: "usdc",
inputs: readonly []inputs: [],
outputs: readonly [{
readonly name: "";
readonly type: "address";
readonly internalType: "contract ERC20Mintable";
}]outputs: [
{
name: ""name: "",
type: "address"type: "address",
internalType: "contract ERC20Mintable"internalType: "contract ERC20Mintable",
},
],
stateMutability: "view"stateMutability: "view",
},
{
type: "function"type: "function",
name: "weth"name: "weth",
inputs: readonly []inputs: [],
outputs: readonly [{
readonly name: "";
readonly type: "address";
readonly internalType: "contract ERC20Mintable";
}]outputs: [
{
name: ""name: "",
type: "address"type: "address",
internalType: "contract ERC20Mintable"internalType: "contract ERC20Mintable",
},
],
stateMutability: "view"stateMutability: "view",
},
] as type const = readonly [{
readonly type: "constructor";
readonly inputs: readonly [];
readonly stateMutability: "nonpayable";
}, {
readonly type: "function";
readonly name: "mint";
readonly inputs: readonly [{
readonly name: "amount1";
readonly type: "uint256";
readonly internalType: "uint256";
}, {
readonly name: "amount2";
readonly type: "uint256";
readonly internalType: "uint256";
}];
readonly outputs: readonly [];
readonly stateMutability: "nonpayable";
}, {
readonly type: "function";
readonly name: "swapUSDCtoWETH";
readonly inputs: readonly [{
readonly name: "amountIn";
readonly type: "uint256";
readonly internalType: "uint256";
}, {
...;
}];
readonly outputs: readonly [];
readonly stateMutability: "nonpayable";
}, {
...;
}, {
...;
}, {
...;
}]const;
Next steps
Build more: