Klaytn Multicall
Built for inevitable-changes/bento
Inspired by makerdao/multicall and dopex-io/web3-multicall
📦
Installation
# Yarn
yarn install klaytn-multicall
# NPM
npm install klaytn-multicall
🚀
Usage
import { Multicall } from 'klaytn-multicall';
const caver = new Caver(...);
const multicall = new Multicall({ provider });
const staking = new caver.klay.Contract(...);
const calls = [
staking.methods.balanceOf(
'0x7777777141f111cf9f0308a63dbd9d0cad3010c4',
),
staking.methods.rewardsOf(
'0x7777777141f111cf9f0308a63dbd9d0cad3010c4',
),
];
await multicall.aggregate(calls)
.then((console.log));
Helpers live inside
getEthBalance
: Gets theETHKLAY balance of an addressgetBlockHash
: Gets the block hashgetLastBlockHash
: Gets the last blocks hashgetCurrentBlockTimestamp
: Gets the current block timestampgetCurrentBlockDifficulty
: Gets the current block difficultygetCurrentBlockGasLimit
: Gets the current block gas limitgetCurrentBlockCoinbase
: Gets the current block coinbase
const multicall = new Multicall({ provider });
const calls = [
staking.methods.balanceOf('0x7777777141f111cf9f0308a63dbd9d0cad3010c4'),
staking.methods.rewardsOf('0x7777777141f111cf9f0308a63dbd9d0cad3010c4'),
// Queries KLAY balance of address
multicall.contract.methods.getEthBalance(
'0x7777777141f111cf9f0308a63dbd9d0cad3010c4',
),
multicall.contract.methods.getBlockHash(103742609),
multicall.contract.methods.getLastBlockHash(),
];
await multicall.aggregate(calls).then(console.log);
Customization
You can inject contract address of your custom implementation, too:
new Multicall({
provider,
multicallV2Address: '0xd11dfc2ab34abd3e1abfba80b99aefbd6255c4b8',
});
multicallV2Address
defaults to 0xd11dfc2ab34abd3e1abfba80b99aefbd6255c4b8
(Multicall2 deployed in Cypress).