> For the complete documentation index, see [llms.txt](https://spock-analytics.gitbook.io/introduction/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://spock-analytics.gitbook.io/introduction/configuration/adapter/functions-we-have-written-so-you-dont-have-to/multicall.md).

# Multicall

Multicall simply aggregates multiple contract calls into a single JSON RPC request.

### Overview

In order to extract a large amount of data in an efficient way we have used Uniswap Multicall Contract for all JSON RPC requests in adapters.

We have coded a JS wrapper over the contracts and placed it in the `abi`  module of our adapter SDK  `@spockanalytics/base`. You can use it for contract calls in your project adapter.&#x20;

### Multicall.singleContractMultipleData

Execute multiple inputs for a single contract.

**Usage**

{% code overflow="wrap" %}

```
abi.Multicall.singleContractMultipleData<Erc20>({
    address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
    chain: 1,
    contractInterface: Erc20_factory.createInterface(),
    fragment: 'balanceOf',
    callInput: ['0xF04a5cC80B1E94C69B48f5ee68a08CD2F09A7c3E','0x2F0b23f53734252Bda2277357e97e1517d6B042A']
});
```

{% endcode %}

<table><thead><tr><th width="182">Argument</th><th width="156.66666666666669">Type</th><th>Description</th></tr></thead><tbody><tr><td>address</td><td>string</td><td>contract address</td></tr><tr><td>blockNumber</td><td>number<br><mark style="color:green;">optional</mark></td><td>Block number at which you want to query</td></tr><tr><td>chain</td><td>number</td><td>Network chainId</td></tr><tr><td>contractInterface</td><td>Interface</td><td>Interface of contract generated through typechain</td></tr><tr><td>fragment</td><td>string</td><td>Method name of contract</td></tr><tr><td>callInput</td><td>OptionalMethodInputs</td><td>Input parameters</td></tr></tbody></table>

### Multicall.multipleContractMultipleData

Execute multiple inputs for multiple contracts.

**Usage**

{% code overflow="wrap" fullWidth="true" %}

```
abi.Multicall.multipleContractMultipleData<Erc20>({
    address: ['0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2','0x37c997b35c619c21323f3518b9357914e8b99525'],
    chain: 1,
    contractInterface: Erc20_factory.createInterface(),
    fragment: 'balanceOf',
    callInput: ['0xF04a5cC80B1E94C69B48f5ee68a08CD2F09A7c3E','0x2F0b23f53734252Bda2277357e97e1517d6B042A']
})
```

{% endcode %}

<table><thead><tr><th width="184">Argument</th><th width="157">Type</th><th>Description</th></tr></thead><tbody><tr><td>address</td><td>string[]</td><td>Contract addresses</td></tr><tr><td>blockNumber</td><td>number<br><mark style="color:green;">optional</mark></td><td>Block at which you want to query</td></tr><tr><td>chain</td><td>number</td><td>Network chainId</td></tr><tr><td>contractInterface</td><td>Interface</td><td>Interface of contract generated through typechain</td></tr><tr><td>fragment</td><td>string</td><td>Method name of contract</td></tr><tr><td>callInput</td><td>OptionalMethodInputs</td><td>Input parameters</td></tr></tbody></table>

### Multicall.multipleContractSingleData

Execute single input for multiple contracts.

**Usage**

{% code overflow="wrap" fullWidth="true" %}

```
abi.Multicall.multipleContractSingleData<Erc20>({
    address: ['0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2','0x37c997b35c619c21323f3518b9357914e8b99525'],
    chain: 1,
    contractInterface: Erc20_factory.createInterface(),
    fragment: 'balanceOf',
    callInput: ['0xF04a5cC80B1E94C69B48f5ee68a08CD2F09A7c3E']
})
```

{% endcode %}

<table><thead><tr><th width="184">Argument</th><th width="156">Type</th><th>Description</th></tr></thead><tbody><tr><td>address</td><td>string</td><td>Contract address</td></tr><tr><td>blockNumber</td><td>number<br><mark style="color:green;">optional</mark></td><td>Block at which you want to query</td></tr><tr><td>chain</td><td>number</td><td>Network chainId</td></tr><tr><td>contractInterface</td><td>Interface</td><td>Interface of contract generated through typechain</td></tr><tr><td>fragment</td><td>string</td><td>Method name of contract</td></tr><tr><td>callInput</td><td>OptionalMethodInputs<br><mark style="color:green;">optional</mark></td><td>Input parameters</td></tr></tbody></table>

### Multicall.execute

Execute multiple calls in one request.

&#x20;**Usage**

{% code overflow="wrap" fullWidth="true" %}

```
const WETH = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
const contractInterface = Erc20_factory.createInterface();

const calls = [
  new abi.Call<Erc20>({address:WETH, contractInterface, fragment:"name"}),
  new abi.Call<Erc20>({address:WETH, contractInterface, fragment:"symbol"}),
  new abi.Call<Erc20>({address:WETH, contractInterface, fragment:"decimals"})
];

abi.Multicall.execute({calls, chain:1});
```

{% endcode %}

**Call**

<table><thead><tr><th width="184">Argument</th><th width="157">Type</th><th>Description</th></tr></thead><tbody><tr><td>address</td><td>string</td><td>Contract address</td></tr><tr><td>contractInterface</td><td>Interface</td><td>Interface of contract generated through typechain.</td></tr><tr><td>fragment</td><td>string</td><td>Method name of contract</td></tr><tr><td>callInput</td><td>OptionalMethodInputs<br><mark style="color:green;">optional</mark></td><td>Input parameters</td></tr></tbody></table>

**Execute**

<table><thead><tr><th width="184">Argument</th><th width="159">Type</th><th>Description</th></tr></thead><tbody><tr><td>blockNumber</td><td>number<br><mark style="color:green;">optional</mark></td><td>Block at which you want to query</td></tr><tr><td>calls</td><td>Call[]</td><td>Calls to be executed</td></tr><tr><td>chain</td><td>number</td><td>Network chainId</td></tr><tr><td>disableChunk</td><td>boolean</td><td>Disable chunk calls on out of gas error</td></tr></tbody></table>

### Call Params

{% code overflow="wrap" fullWidth="true" %}

```
import { BigNumber } from '@ethersproject/bignumber';

type MethodArg = string | number | BigNumber;
type OptionalMethodInputs =
  | Array<MethodArg | MethodArg[] | undefined>
  | undefined;
```

{% endcode %}

### Call Result

The return type of each method.

{% code overflow="wrap" fullWidth="true" %}

```
//each method return an array of CallResult promise
// Promise<Array<CallResult>>

interface CallResult {
  call: {
    address: string;
    input: OptionalMethodInputs;
  };
  output: any;
  success: boolean;
}
```

{% endcode %}
