1

The method to aggregate functions belonging to contracts is given in this library: https://pypi.org/project/web3-multicall/

But my question is, how can I aggregate a basic web3 function (that is not a part of any contract) too using Multicall?

In my case, I want to get multiple transaction receipts/timestamps (using the web3.eth.get_transaction_receipt() or web3.eth.getBlock().timestamp function) via a single API call.

Would it be possible for them or any other basic non-contract functions such as web.eth.eth_balance() to be used with the Multicall feature?

3 Answers 3

1

I will give you an example. Imagine you want to get balances of 100 addresses.

There are two general options:

  1. Your Backend/Frontend calls blockchain a 100 times.

  2. You write a SmartContract function that receives an array of 100 addresses and in turn returns an array of 100 corresponding balances.

The second option is the way to go.

2
  • Thank you for the answer. Do you know any public SmartContract which returns the timestamp of a block (similar to web3.eth.getBlock().timestamp), that I can directly use? Commented Aug 4, 2022 at 19:19
  • @DEEPAKS.V. - Yes, the Multicall contract (linked in another comment) does have a getCurrentBlockTimestamp to fetch that. Just note that you wouldn't be able to provide an arbitrary block number; it only shows the most recent block's timestamp. Commented Jul 25, 2023 at 15:35
0

You will get answer at https://github.com/mds1/multicall, a smart contract on many chains.

1
  • You aren't answering the question: how to use multicall to call a non contract function in web3 python?
    – Ismael
    Commented Feb 23, 2023 at 22:21
0

Multicall3 contract provides a bunch of wrappers around built-in Solidity functions, for example getCurrentBlockTimestamp. You just need add their calls to Multicall3.aggregate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.