Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Dec 18, 2023 · 0 comments

Comments

@LygmaBawlz
Copy link

LygmaBawlz commented Dec 18, 2023

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=INVALID_ARGUMENT, 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,
});

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant