Enhanced multicall sdk to safely make multicalls within the gas limit.
npm install @summitx/multicallEnhanced multicall sdk to safely make multicalls within the gas limit.
Inspired by the 1inch multicall.
``bash`
$ pnpm add @summitx/multicall @summitx/sdk viem
By default the calls will be splitted into chunks based on gas limit of each call and the rpc call gas limit of the chain
`typescript
import { ChainId } from "@summitx/chains";
import { multicallByGasLimit, MulticallRequestWithGas } from "@summitx/multicall";
const calls: MulticallRequestWithGas[] = [
{
// Target contract to call
target: "0x",
// Encoded call data
callData: "",
// The maximum gas limit set to this single call
gasLimit: 1_000_000,
},
];
const { results, blockNumber } = await multicallByGasLimit(calls, {
chainId: ChainId.CAMP,
// Rpc client. Please refer to PublicClient from viem
client,
});
for (const { success, result, gasUsed } of results) {
if (success) {
// Decode result
decodeResult(result);
}
}
`
The rpc call gas limit can be overriden if provided. Once provided, the multicall sdk won't ask for the gas limit from on chain.
`typescript`
const { results, blockNumber } = await multicallByGasLimit(calls, {
chainId: ChainId.CAMP,
client,
gasLimit: 150_000_000,
});
`typescript
import { ChainId } from "@summitx/chains";
import { getGasLimitOnChain } from "@summitx/multicall";
// Get the rpc call gas limit of the specified chain
const gasLimit = await getGasLimitOnChain(ChainId.CAMP);
``
For supported chains and contract addresses, please refer to multicall contracts.