A library to do multiple calls via a single eth_call using web3.
- via yarn
yarn add @dopex-io/web3-multicall- via npm
npm i @dopex-io/web3-multicall- 
With chainIdimport Multicall from '@dopex-io/web3-multicall'; import erc20Abi from './abi/erc20.json'; async function main() { const web3 = new Web3(provider /* Your Web3 provider here */); const multicall = new Multicall({ chainId: 1, provider: 'Your Web3 provider here', defaultBlock: 1000 /* Optional */ }); ... } main() 
- 
With custom Multicall address import Multicall from '@dopex-io/web3-multicall'; import erc20Abi from './abi/erc20.json'; async function main() { const web3 = new Web3(provider /* Your Web3 provider here */); const multicall = new Multicall({ multicallAddress: "The address of the deployed multicall contract", provider: 'Your Web3 provider here', defaultBlock: 1000 /* Optional */ }); ... } main(); 
const dpxContract = new web3.eth.Contract(dpxAddress, erc20Abi);
const balances = await multicall.aggregate([
  dpxContract.methods.balanceOf('Address 1'),
  dpxContract.methods.balanceOf('Address 2'),
  multicall.getEthBalance('Address 3'),
]);
console.log('DPX balance of Address 1', balances[0]);
console.log('DPX balance of Address 2', balances[1]);
console.log('ETH balance of Address 3', balances[2]);- 
getEthBalanceGets the ETH balance of an addressconst ethBalance = multicall.getEthBalance('address'); 
- 
getBlockHashGets the block hashconst blockHash = multicall.getBlockHash(blockNumber); 
- 
getLastBlockHashGets the last blocks hashconst lastBlockHash = multicall.getLastBlockHash(); 
- 
getCurrentBlockTimestampGets the current block timestampconst currentBlockTimestamp = multicall.getCurrentBlockTimestamp(); 
- 
getCurrentBlockDifficultyGets the current block difficultyconst currentBlockDifficulty = multicall.getCurrentBlockDifficulty(); 
- 
getCurrentBlockGasLimitGets the current block gas limitconst currentBlockGasLimit = multicall.getCurrentBlockGasLimit(); 
- 
getCurrentBlockCoinbaseGets the current block coinbaseconst currentBlockCoinbase = multicall.getCurrentBlockCoinbase(); 
This project is licensed under the MIT License - Copyright (c) 2023 Dopex