# Multicall

For any write function, the SDK includes a corresponding call data version that returns the call data information instead of submitting a transaction. These objects can then be aggregated and passed into the [`multicall`](#multicall) function in order to batch multiple operations into one transaction.

### <mark style="color:purple;">multicall</mark>

Batch multiple write operations in one transaction.

```typescript
const multicallResult = await hatsClient.multicall({
    account,
    calls,
});
```

***Arguments***:

```typescript
{
    account: Account | Address;
    calls: {
      functionName: string;
      callData: Hex;
    }[];
}
```

* `account` - Viem account (Address for JSON-RPC accounts or Account for other types).
* `calls` - An array of call data objects, each one includes the function name and the call data to pass to the function.

***Response***:

```typescript
{
  status: "success" | "reverted";
  transactionHash: `0x${string}`;
  gasUsed: bigint;
  hatsCreated: bigint[];
  hatsMinted: {
    hatId: bigint;
    wearer: `0x${string}`;
  }[];
  hatsBurned: {
    hatId: bigint;
    wearer: `0x${string}`;
  }[];
  hatStatusChanges: {
    hatId: bigint;
    newStatus: "active" | "inactive";
  }[];
  wearerStandingChanges: {
    hatId: bigint;
    wearer: `0x${string}`;
    newStanding: "good" | "bad";
  }[];
}
```

* `status` - "success" if transaction was successful, "reverted" if transaction reverted.
* `transactionHash` - transaction's hash.
* `gasUsed` - Amount of gas used in the transaction.
* `hatsCreated` - Hats IDs of any newly created hats.
* `hatsMinted` - For every hat minted, contains an object with the hat ID and the new wearer address.
* `hatsBurned` - For every hat burned, contains an object with the hat ID and the wearer address.
* `hatStatusChanges` - For every hat status change, contains on object with the hat ID and the new status.
* `wearerStandingChanges` - For every wearer standing status change, contains an object with the hat ID, the wearer address and the new standing.

***Example:***

Create a new top-hat, then create one child hat and mint the child hat to a new wearer.

```typescript
const mintTopHatCallData = await hatsClient.mintTopHatCallData({
    target,
    details,
    imageURI,
});

const createHatCallData = await hatsClient.createHatCallData({
    admin,
    details,
    maxSupply,
    eligibility,
    toggle,
    mutable,
    imageURI,
});

const mintHatCallData = await hatsClient.mintHatCallData({
    hatId,
    wearer,
});

const multiCallResult = await hatsClient.multicall({
    account,
    calls: [mintTopHatCallData, createHatCallData, mintHatCallData],
});
```

### <mark style="color:purple;">multicallPreFlightCheck</mark>

Simulates the multicall function with the provided calls.  The function has no return value, will revert on failure, with a custom error.&#x20;

<pre class="language-typescript"><code class="lang-typescript"><strong>await hatsClient.multicallPreFlightCheck({
</strong>    account,
    calls,
});
</code></pre>

***Arguments***:

```typescript
{
    account: Account | Address;
    calls: {
      functionName: string;
      callData: Hex;
    }[];
}
```

* `account` - Viem account (Address for JSON-RPC accounts or Account for other types).
* `calls` - An array of call data objects, each one includes the function name and the call data to pass to the function.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hatsprotocol.xyz/for-developers/v1-sdk/core/multicall.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
