cavanmflynn / ethers-multicall

Make multiple Ethereum network requests in a single HTTP query. ethcall for ethers v5.
MIT License
224 stars 99 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) #60

Open LygmaBawlz opened 10 months ago

LygmaBawlz commented 10 months ago

Hello, I am trying to run a multicall using your API (thank you by the way), however I am running in to the following issue.

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

The following is my code for running the multiCall API.

` async loadDataUsingMulticall() { const { web3 } = this.state; var multicall = null;

// Your multicall code here

console.log("test zero -");

multicall = new Multicall({
  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);

//THE ISSUE COULD BE HERE TO THE WAY: callResults.results.<nameofId>.callsReturnContext[0].returnValues
// 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,
});

}`