2

I'm trying to build a multicall method (standard swap) with ethers library and JS but running into this error:

(0, properties_1.defineReadOnly)(this, "fragments", abi.map(function (fragment) {
                                                                ^

TypeError: abi.map is not a function

This is my code and I'm totally sure I'm doing something wrong as this whole multicall is new to me.

Also, how do I add another method into the same multicall? Like an approve of a token. Has someone a working example?

p.s.: I dont want to use web3, rather stick to ethers lib.

const params = {
      amountIn: purchaseAmount,
      amountOutMin: 0,
      path: tokenspair,
      to: publicKey
    }

    const data = await ethers.utils.Interface(abi).encodeFunctionData("swapExactTokensForTokens", params)
    
    let unsignedTx = await _router.populateTransaction.multicall(
      data,
      {
        type: 2,
        maxFeePerGas: maxFeePerGas,
        maxPriorityFeePerGas: maxPriorityFeePerGas,
        gasLimit: gasLimit,
        nonce: currentNonce,
        deadline: Date.now() + 1000 * 60 * 5
      }
    )

    unsignedTx.chainId = chainID
    signedTx = await _wallet.signTransaction(unsignedTx)

I checked the ABI and I have the method "swapExactTokensForTokens" in there correctly.

Thanks a ton for helping!

0 Answers0