Batching
The multicall()
method in V2 registry lets users queue up multiple delegations and submit them all in a single transaction. This is more gas-efficient and saves user time.
The function is simple, use a frontend library to pack each method call into its bytes representation then submit an array of byte function calls. This can be used for both writes and reads.
function multicall(bytes[] calldata data) external payable override returns (bytes[] memory results) {
results = new bytes[](data.length);
bool success;
unchecked {
for (uint256 i = 0; i < data.length; ++i) {
//slither-disable-next-line calls-loop,delegatecall-loop
(success, results[i]) = address(this).delegatecall(data[i]);
if (!success) revert MulticallFailed();
}
}
}
Last updated