joshstevens19 / ethereum-multicall

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

setting block number is not effecting the request #99

Open HadiEsna opened 4 months ago

HadiEsna commented 4 months ago

The Problem When I try to change the block number of the request, it doesn't effect the result at all I were able to fix it by changing the way we feed the blocknumber in the contract call. (please take look at here Can you check if I'm doing sth wrong or it's a bug with library. I can create a PR too if it's needed.

Code to replicate


    let calls: any = [];
calls.push({
      reference: "CHAINLINK-PRICE" ,
      contractAddress: 0x13e3Ee699D1909E989722E753853AE30b17e08c5,
      abi: oracleABI, // chainlink oracle abi (copy it from [here](https://optimistic.etherscan.io/address/0x13e3Ee699D1909E989722E753853AE30b17e08c5#code)
      calls: [{ reference: feed, methodName: "latestRoundData", methodParameters: [] }],
    });
    let data = await multicall
      .call(calls, {
        blockNumber: 121357248, // around 30 days ago (Jun-13-2024)
      })
      .catch((e: any) => {
        console.log("error", e);
        return {};
      });
          console.log("data2", BigInt(data.results["CHAINLINK-PRICE"].callsReturnContext[0].returnValues[3].hex).toString());  // update timestamp (which shows now, not 30 days ago)
          console.log("block number", data.blockNumber);
radisa-bogdanovic commented 4 months ago

I had a similar issue with Arbitrum One or Arbitrum Nova, I'm not sure wich one exactly. Request was eth_getBalance. It always returned the latest block but also returned different result balances (i guessed based of the number of the block). I tested the closest block to check if it returned a valid result, and it did. What I did was to include the block from the request into the result table, along with its timestamp and everything else. If it's returning the correct data, you might want to implement a workaround like I did.

HadiEsna commented 4 months ago

How did you solve the issue? (apart from including the output in the result table)

radisa-bogdanovic commented 3 months ago

Hmm, i didn't actualy fix it in the libary and i dont know how to do that 2 be honest. I just create workaround. So basicaly if i need blockNumber or timeStamp of requested data i just call getBlock(121357248) method from web3 and get data for that block. I test balances in time 1 year ago, 1 month ago, 1 day ago and many more and for the latest he return correct data for the latest balance or closest block to them. For oldest data i dont find a way to compare them but i see difference between them and i workaround with theory that only blockNumber in 'response' is incorrect. in my case that solve a problem wich i had.