Multicall3
Title: Multicall3
Authors: Michael Elliot, Joshua Levine, Nick Johnson, Andreas Bigger, Matt Solomon
Aggregate results from multiple function calls.
Multicall and Multicall2 backwards-compatible.
Source-compatible with mds1/multicall3; pragma updated for this repository.
Aggregate methods are payable to match the standard Multicall3 ABI.
Functions
aggregate
Backwards-compatible call aggregation with Multicall.
function aggregate(Call[] calldata calls)
public
payable
returns (uint256 blockNumber, bytes[] memory returnData);
Parameters
| Name | Type | Description |
|---|---|---|
calls | Call[] | An array of Call structs. |
Returns
| Name | Type | Description |
|---|---|---|
blockNumber | uint256 | The block number where the calls were executed. |
returnData | bytes[] | An array of bytes containing the responses. |
tryAggregate
Backwards-compatible with Multicall2.
Aggregate calls without requiring success.
function tryAggregate(
bool requireSuccess,
Call[] calldata calls
)
public
payable
returns (Result[] memory returnData);
Parameters
| Name | Type | Description |
|---|---|---|
requireSuccess | bool | If true, require all calls to succeed. |
calls | Call[] | An array of Call structs. |
Returns
| Name | Type | Description |
|---|---|---|
returnData | Result[] | An array of Result structs. |
tryBlockAndAggregate
Backwards-compatible with Multicall2.
Aggregate calls and allow failures using tryAggregate.
function tryBlockAndAggregate(
bool requireSuccess,
Call[] calldata calls
)
public
payable
returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData);
Parameters
| Name | Type | Description |
|---|---|---|
requireSuccess | bool | If true, require all calls to succeed. |
calls | Call[] | An array of Call structs. |
Returns
| Name | Type | Description |
|---|---|---|
blockNumber | uint256 | The block number where the calls were executed. |
blockHash | bytes32 | The hash of the block where the calls were executed. |
returnData | Result[] | An array of Result structs. |
blockAndAggregate
Backwards-compatible with Multicall2.
Aggregate calls and allow failures using tryAggregate.
function blockAndAggregate(Call[] calldata calls)
public
payable
returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData);
Parameters
| Name | Type | Description |
|---|---|---|
calls | Call[] | An array of Call structs. |
Returns
| Name | Type | Description |
|---|---|---|
blockNumber | uint256 | The block number where the calls were executed. |
blockHash | bytes32 | The hash of the block where the calls were executed. |
returnData | Result[] | An array of Result structs. |
aggregate3
Aggregate calls, ensuring each returns success if required.
function aggregate3(Call3[] calldata calls)
public
payable
returns (Result[] memory returnData);
Parameters
| Name | Type | Description |
|---|---|---|
calls | Call3[] | An array of Call3 structs. |
Returns
| Name | Type | Description |
|---|---|---|
returnData | Result[] | An array of Result structs. |
aggregate3Value
Aggregate calls with a msg value.
Reverts if msg.value is not equal to the sum of the call values.
function aggregate3Value(Call3Value[] calldata calls)
public
payable
returns (Result[] memory returnData);
Parameters
| Name | Type | Description |
|---|---|---|
calls | Call3Value[] | An array of Call3Value structs. |
Returns
| Name | Type | Description |
|---|---|---|
returnData | Result[] | An array of Result structs. |
getBlockHash
Returns the block hash for the given block number.
function getBlockHash(uint256 blockNumber) public view returns (bytes32 blockHash);
Parameters
| Name | Type | Description |
|---|---|---|
blockNumber | uint256 | The block number. |
getBlockNumber
Returns the block number.
function getBlockNumber() public view returns (uint256 blockNumber);
getCurrentBlockCoinbase
Returns the block coinbase.
function getCurrentBlockCoinbase() public view returns (address coinbase);
getCurrentBlockDifficulty
Returns the block prevrandao value.
function getCurrentBlockDifficulty() public view returns (uint256 difficulty);
getCurrentBlockGasLimit
Returns the block gas limit.
function getCurrentBlockGasLimit() public view returns (uint256 gaslimit);
getCurrentBlockTimestamp
Returns the block timestamp.
function getCurrentBlockTimestamp() public view returns (uint256 timestamp);
getEthBalance
Returns the native-token balance of a given address.
function getEthBalance(address addr) public view returns (uint256 balance);
getLastBlockHash
Returns the block hash of the last block.
function getLastBlockHash() public view returns (bytes32 blockHash);
getBasefee
Gets the base fee of the given block.
Can revert if the BASEFEE opcode is not implemented by the given chain.
function getBasefee() public view returns (uint256 basefee);
getChainId
Returns the chain id.
function getChainId() public view returns (uint256 chainid);
Structs
Call
struct Call {
address target;
bytes callData;
}
Call3
struct Call3 {
address target;
bool allowFailure;
bytes callData;
}
Call3Value
struct Call3Value {
address target;
bool allowFailure;
uint256 value;
bytes callData;
}
Result
struct Result {
bool success;
bytes returnData;
}