Skip to main content

Module: utils/multicall

MultiCaller

Util for executing multi calls against the MultiCallV2 contract

Properties

PropertyTypeDescription
readonly addressstringAddress of multicall contract

Methods

getBlockNumberInput()

getBlockNumberInput(): CallInput< BigNumber >

Get the call input for the current block number

Returns

CallInput\< BigNumber >

Source

arbitrum-sdk/src/lib/utils/multicall.ts:163


getCurrentBlockTimestampInput()

getCurrentBlockTimestampInput(): CallInput< BigNumber >

Get the call input for the current block timestamp

Returns

CallInput\< BigNumber >

Source

arbitrum-sdk/src/lib/utils/multicall.ts:179


getTokenData()

getTokenData&lt;T&gt;(erc20Addresses, options?): Promise< TokenInputOutput< T >[] >

Multicall for token properties. Will collect all the requested properies for each of the supplied token addresses.

Type parameters
Parameter
T extends undefined | TokenMultiInput
Parameters
ParameterTypeDescription
erc20Addressesstring[]
options?TDefaults to just 'name'
Returns

Promise\< TokenInputOutput\< T >[] >

Source

arbitrum-sdk/src/lib/utils/multicall.ts:261


multiCall()

multiCall<T, TRequireSuccess>(params, requireSuccess?): Promise< DecoderReturnType< T, TRequireSuccess > >

Executes a multicall for the given parameters Return values are order the same as the inputs. If a call failed undefined is returned instead of the value.

To get better type inference when the individual calls are of different types create your inputs as a tuple and pass the tuple in. The return type will be a tuple of the decoded return types. eg.

const inputs: [
CallInput<Awaited<ReturnType<ERC20['functions']['balanceOf']>>[0]>,
CallInput<Awaited<ReturnType<ERC20['functions']['name']>>[0]>,
] = [
{
targetAddr: token.address,
encoder: () => token.interface.encodeFunctionData('balanceOf', ['']),
decoder: (returnData: string) =>
token.interface.decodeFunctionResult('balanceOf', returnData)[0],
},
{
targetAddr: token.address,
encoder: () => token.interface.encodeFunctionData('name'),
decoder: (returnData: string) => token.interface.decodeFunctionResult('name', returnData)[0],
},
];

const res = await multiCaller.call(inputs);
Type parameters
Parameter
T extends CallInput\< unknown >[]
TRequireSuccess extends boolean
Parameters
ParameterTypeDescription
paramsT
requireSuccess?TRequireSuccessFail the whole call if any internal call fails
Returns

Promise\< DecoderReturnType\< T, TRequireSuccess > >

Source

arbitrum-sdk/src/lib/utils/multicall.ts:227


fromProvider()

static fromProvider(provider): Promise< MultiCaller >

Finds the correct multicall address for the given provider and instantiates a multicaller

Parameters
ParameterTypeDescription
providerProvider
Returns

Promise\< MultiCaller >

Source

arbitrum-sdk/src/lib/utils/multicall.ts:132


CallInput

CallInput: &lt;T&gt;object;

Input to multicall aggregator

Type parameters

Parameter
T

Type declaration

MemberTypeDescription
decoder(returnData) => TFunction to decode the result of the call
encoder() => stringFunction to produce encoded call data
targetAddrstringAddress of the target contract to be called

Source

arbitrum-sdk/src/lib/utils/multicall.ts:37