Calls from a loop
To test with the traditional method, we will go through the array of addresses, and within a map
loop, we will return the result of each query, one by one, until we reach the 1,000 addresses that the file has. To do this, we will do a function like the following:
Here we instantiate the compound comptroller contract and call the account liquidity function for each address.
Make a Multicall call
When using the Multicall call, this function would have to be changed a little, leaving the form as follows:
What we do here is to make use of the Provider
and Contract
classes from the Multicall package. First we initialize this provider, passing our provider web3
and the contract with the address and its ABI.
Once we have it created, we do the same process as before. With a map
, we make the calls to the account liquidity function. But in this case, we are not sending them to the network but grouping them in an array. Once this array is created, the all
function of the created provider is called, and this makes the call to the network.