@pintswap-v3/multicall
TypeScript icon, indicating that this package has built-in type declarations

3.5.8 • Public • Published

Pink Multicall

Enhanced multicall sdk to safely make multicalls within the gas limit.

Inspired by the 1inch multicall.

Install

$ pnpm add @pintswap-v3/multicall @pintswap-v3/sdk viem

Usage

Basic usage

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

import { ChainId } from '@pintswap-v3/chains'
import { multicallByGasLimit, MulticallRequestWithGas } from '@pintswap-v3/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.BSC,

  // Rpc client. Please refer to `PublicClient` from viem
  client,
})

for (const { success, result, gasUsed } of results) {
  if (success) {
    // Decode result
    decodeResult(result)
  }
}

Advanced usage

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.

const { results, blockNumber } = await multicallByGasLimit(calls, {
  chainId: ChainId.BSC,
  client,
  gasLimit: 150_000_000,
})

Other utilities

Get multicall gas limit

import { ChainId } from '@pintswap-v3/chains'
import { getGasLimitOnChain } from '@pintswap-v3/multicall'

// Get the rpc call gas limit of the specified chain
const gasLimit = await getGasLimitOnChain(ChainId.BSC)

Supported chains

For supported chains and contract addresses, please refer to multicall contracts.

Readme

Keywords

none

Package Sidebar

Install

npm i @pintswap-v3/multicall

Weekly Downloads

0

Version

3.5.8

License

none

Unpacked Size

191 kB

Total Files

31

Last publish

Collaborators

  • pintswap-v3