Approving ERC20s in our multicall

Before calling a contract with tokens from a swap, you must first approve the contract to spend the Squid Multicall contract's balance. Below is the Javascript code to approve the multicall's current balance of the tokens.

import erc20Abi from "./abi/erc20.json";

const sushiRouterAddress = "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506"

const usdcTokenAddress = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
const usdcContractInterface = new ethers.utils.Interface(erc20Abi as any);

const approveEncodeData = usdcContractInterface.encodeFunctionData(
        "0" // Amount to approve. See below for why this is zero.

const approveCall = {
    callType: 1,
    target: usdcTokenAddress,
    value: "0", // native value to be sent with call
    callData: approveEncodeData,
    payload: {
        tokenAddress: usdcTokenAddress, // balance of this token replaces 0 on line 13
        inputPos: 1
    estimatedGas: "400000"

You will see that the approve transaction has "0" as the approval amount. This is because the approval amount set to be the current balance of the ERC20 token specified in payload line 22


payload is an object passed into the Squid smart contracts for call types 1 and ?? It is used for patching the current balance of a token into the calldata of the next call. This allows us to make long strings of calls, even if the output of each call is not deterministic (e.g. slippage).

Last updated