Skip to main content

Batch Calls

Superfluid's SDK Core allows you to batch multiple operations into a single transaction. This guide explains how to utilize the BatchCall class to achieve this.

Supported Operations

List of Operations Supported by BatchCall

  • ERC20_APPROVE (SuperToken only)
  • ERC20_TRANSFER_FROM
  • SUPERTOKEN_UPGRADE
  • SUPERTOKEN_DOWNGRADE
  • SUPERFLUID_CALL_AGREEMENT
  • CALL_APP_ACTION

SUPERFLUID_CALL_AGREEMENT refers to operations related to CFA or IDA, like createFlow, updateIndex, distribute, etc. CALL_APP_ACTION refers to operations created from calling a function on a super app.

Framework Based Initialization

Initializing BatchCall via Framework

import { Framework } from "@superfluid-finance/sdk-core";
import { ethers } from "ethers";

const provider = new ethers.providers.InfuraProvider("matic", "<INFURA_API_KEY>");

const sf = await Framework.create({
chainId: 137, // Change to your network's chain ID
provider
});

const signer = sf.createSigner({ privateKey: "<TEST_ACCOUNT_PRIVATE_KEY>", provider });
const batchCall = sf.batchCall([/* Replace with your operations */]);

Direct Initialization

Initializing BatchCall Directly

import { BatchCall } from "@superfluid-finance/sdk-core";

const batchCall = new BatchCall({
hostAddress: "0x3E14dC1b13c488a8d5D310918780c983bD5982E7",
operations: [/* Replace with your operations */]
});

Usage

Creating and Executing Batch Calls

import { Framework } from "@superfluid-finance/sdk-core";
import { ethers } from "ethers";

const provider = new ethers.providers.InfuraProvider("matic", "<INFURA_API_KEY>");

const sf = await Framework.create({
chainId: 137, // Replace with your chain ID
provider
});

const daix = await sf.loadSuperToken("0x745861AeD1EEe363b4AaA5F1994Be40b1e05Ff90");

const signer = sf.createSigner({ privateKey: "<TEST_ACCOUNT_PRIVATE_KEY>", provider });
const fromAddress = "0xabc";
const paymentAddress = "0xdef";
const approveOp = daix.approve({ receiver: paymentAddress, amount: "10000" });
const transferFromOp = daix.transferFrom({
sender: fromAddress,
receiver: paymentAddress,
amount: "10000"
});
const batchCall = sf.batchCall([approveOp, transferFromOp]);
const txn = await batchCall.exec(signer);

// Example of creating an operation from a super app function
const superAppInterface = new ethers.utils.Interface(/* Replace with SUPER_APP_ABI */);

const callData = superAppInterface.encodeFunctionData("transferERC20", [
/* Replace with your parameters */
]);

const transferOp = sf.host.callAppAction(/* Replace with app address */, callData);

const batchCall = sf.batchCall([transferOp]);
await batchCall.exec(signer);

This guide covers how to use the BatchCall class in the Superfluid SDK Core to batch multiple operations into a single transaction. It includes both framework-based and direct initialization methods, along with examples of creating and executing batch calls.