Skip to main content

Send Batch Transactions

Send Batch Transactions

A batch refers to a group of calls inside a single user operationhe. This can be an approve and send transaction in one call. The executeBatch() method is used.

The executeBatch() method takes in an array of objects. With each object taking in 3 keys: to, value and data.

executeBatch([
{ to, value, data },
{ to, value, data },
{ to, value, data },
]);
ParamTypeStatusDescription
toaddressrequiredThe address where the user want to send Tokens.
valuenumberrequiredThe amount of Tokens the user is sending
dataFunctionEncoded Function Data for Smart Contract Methods

Example: index.ts

import { ethers } from "ethers";
import { FuseSDK } from "@fuseio/fusebox-web-sdk";

const main = async () => {
const credentials = new ethers.Wallet("PRIVATE_KEY");
const apiKey = "API_KEY";
const fuseSDK = await FuseSDK.init(apiKey, credentials);

console.log(`Sender Address is ${fuseSDK.wallet.getSender()}`);

const to = ["EOA_ADDRESS", "EOA_ADDRESS"];

const calls = to.map((x) => {
return {
to: x,
value: ethers.utils.parseEther("0.001"),
data: Uint8Array.from([]),
};
});

const res = await fuseSDK.executeBatch(calls);

console.log(`UserOpHash: ${res?.userOpHash}`);
console.log("Waiting for transaction...");

const receipt = await res?.wait();
console.log("Transaction Hash:", receipt?.transactionHash);
};

main();

Was this page helpful?