joshstevens19 / ethereum-multicall

Ability to call many ethereum constant function calls in 1 JSONRPC request
MIT License
361 stars 90 forks source link

Uncaught (in promise) Error: invalid address (argument="address", value=0, code=INVALID_ARGUMENT, version=address/5.7.0) (argument=null, value=0, code=INVALID_ARGUMENT, version=abi/5.7.0) #80

Closed LygmaBawlz closed 8 months ago

LygmaBawlz commented 8 months ago

Hello,

First of all thank you for putting together ethereum-multicall for us, really appreciate it.

I am running into an issue on my react js code when trying to call multicall. The issue looks like this:

Uncaught (in promise) Error: invalid address (argument="address", value=0, code=INVALID_ARGUMENT, version=address/5.7.0) (argument=null, value=0, code=INVALID_ARGUMENT, version=abi/5.7.0)

I have double checked the addresses and they are correct and they worked when not trying to use multiCall.

The following is my code on how I am calling multiCall

async loadDataUsingMulticall() {
    const { web3 } = this.state;
    var multicall = null;
    console.log("This is the mirror address:",MIRROR_ADDRESS);

    multicall = new Multicall({
      multicallCustomContractAddress: MIRROR_ADDRESS,
      nodeUrl: BSC_RPC_URL,
      web3Instance: web3,
      tryAggregate: true,
    });

    console.log("test zero");

    const contractCallContext = [
      {
        reference: "mirrorBalance",
        contractAddress: MIRROR_ADDRESS,
        abi: MIRRORABI,
        calls: [
          {
            methodName: "balanceOf",
            methodParameters: [this.state.account[0]],
          },
        ],
      },
      {
        reference: "morWholeBurn",
        contractAddress: MIRROR_ADDRESS,
        abi: MIRRORABI,
        calls: [
          {
            methodName: "balanceOf",
            methodParameters: ["0x0000000000000000000000000000000000000000"],
          },
        ],
      },
      {
        reference: "morRFIBurn",
        contractAddress: MIRROR_ADDRESS,
        abi: MIRRORABI,
        calls: [
          {
            methodName: "balanceOf",
            methodParameters: ["0x000000000000000000000000000000000000dead"],
          },
        ],
      },
      {
        reference: "totalFees",
        contractAddress: MIRROR_ADDRESS,
        abi: MIRRORABI,
        calls: [{ methodName: "totalFees", methodParameters: [] }],
      },
      {
        reference: "numFarmers",
        contractAddress: MIRROR_ADDRESS,
        abi: MIRRORABI,
        calls: [{ methodName: "numFarmers", methodParameters: [] }],
      },
    ];

    console.log("test before");
    console.log(MIRROR_ADDRESS);

    // Loop for dynamic method calls like 'farmers' and 'farmingLeaderboard'
    for (let i = 0; i < 5; i++) {
      contractCallContext.push({
        reference: `farmer${i}`,
        contractAddress: MIRROR_ADDRESS,
        abi: MIRRORABI,
        calls: [{ methodName: "farmers", methodParameters: [i] }],
      });
      contractCallContext.push({
        reference: `farmer${i}amt`,
        contractAddress: MIRROR_ADDRESS,
        abi: MIRRORABI,
        calls: [{ methodName: "farmingLeaderboard", methodParameters: [i] }],
      });
    }
    ////////////

    const callResults = await multicall.call(contractCallContext);
    console.log("test)");
    console.log(callResults);

    // Accessing individual results
    const mirrorBalance = Web3.utils.fromWei(
      callResults.results.mirrorBalance.callsReturnContext[0].returnValues[0],
      "ether",
    );
    const morWholeBurn = Web3.utils.fromWei(
      callResults.results.morWholeBurn.callsReturnContext[0].returnValues[0],
      "ether",
    );
    const morRFIBurn = Web3.utils.fromWei(
      callResults.results.morRFIBurn.callsReturnContext[0].returnValues[0],
      "ether",
    );
    const totalFees = Web3.utils.fromWei(
      callResults.results.totalFees.callsReturnContext[0].returnValues[0],
      "ether",
    );
    const numFarmers = parseInt(
      callResults.results.numFarmers.callsReturnContext[0].returnValues[0],
    );
    console.log("This is mirror Balance");
    console.log(mirrorBalance);
    console.log("This is morWhole Burn");
    console.log(morWholeBurn);
    console.log("This is total Farmers");
    console.log(numFarmers);
    // Loop to access farmers and farmingLeaderboard data
    let farmerData = {};
    for (let i = 0; i < 5; i++) {
      farmerData[`farmer${i}`] =
        callResults.results[`farmer${i}`].callsReturnContext[0].returnValues[0];
      farmerData[`farmer${i}amt`] =
        callResults.results[
          `farmer${i}amt`
        ].callsReturnContext[0].returnValues[0];
    }

    // Update state with all the gathered data
    this.setState({
      mirrorBalance,
      morWholeBurn,
      morRFIBurn,
      totalFees,
      numFarmers,
      ...farmerData,
      loadingLeaderBoard: false,
    });
  }
LygmaBawlz commented 8 months ago

Hey, it looks like my ABI had a fault. Closing the issue!

Thank you for your api, its wonderful