There are different implementations of multicall:
- https://github.com/Vectorized/multicaller
- https://github.com/mds1/multicall
- https://github.com/AmazingAng/WTF-Solidity/tree/main/55_MultiCall
In the following section, we will use Multicaller
as an example to illustrate the process.
The main idea of Multicaller
is to aggregate multiple contract function calls into a single one. It's usually to batch contract reads from off-chain apps. However, it could also be used to batch contract writes.
Multiple Contract Reads
ref:
https://github.com/Vectorized/multicaller/blob/main/API.md#aggregate
Multiple Contract Writes
It requires the target contract is compatible with Multicaller
if the target contract needs to read msg.sender
.
ref:
https://github.com/Vectorized/multicaller/blob/main/API.md#aggregatewithsender