# Understanding the batch precompile

## The problem we're solving here

When we try to create modern dApps, the less transactions the user have to sign, the better. That's why this section is dedicated to Moonbeam Batch precompile that allows us to pack several transactions into a bigger one. This is of course convenient from an end-user's perspective but also on a gas-optimization one, as the base fee per transaction is reduced to a single one.

## Access the Batch Precompile

The Batch Precompile can be accessed on Moonbeam and Moonbase Alpha at this predetermined addresses:

`0x0000000000000000000000000000000000000808`

You'll find its Solidity interface on [PureStake's github.](https://github.com/moonbeam-foundation/moonbeam/blob/master/precompiles/batch/Batch.sol)

## The Batch functions

> * **batchSome**(*address\[]* to, *uint256\[]* value, *bytes\[]* callData, *uint64\[]* gasLimit) — performs multiple calls, where the same index of each array combine into the information required for a single subcall. If a subcall reverts, following subcalls will still be attempted
> * **batchSomeUntilFailure**(*address\[]* to, *uint256\[]* value, *bytes\[]* callData, *uint64\[]* gasLimit) — performs multiple calls, where the same index of each array combine into the information required for a single subcall. If a subcall reverts, no following subcalls will be executed
> * **batchAll**(*address\[]* to, *uint256\[]* value, *bytes\[]* callData, *uint64\[]* gasLimit) — performs multiple calls atomically, where the same index of each array combine into the information required for a single subcall. If a subcall reverts, all subcalls will revert

As we can see in this quote, we have 3 ways of integrating the Batch precompile. The difference is on how the batch will behave if one of the subcalls fails.

* batchSome will continue to execute the following subcallls even is one is failing
* batchSomeUntilFailure will abort on failure as its name suggests, avoiding failure
* batchAll will make all subcalls revert if one is failing

## The Batch parameters

> * ***address\[]*****&#x20;to** - an array of addresses to direct subtransactions to, where each entry is a subtransaction
> * ***uint256\[]*****&#x20;value** - an array of native currency values to send in the subtransactions, where the index corresponds to the subtransaction of the same index in the *to* array. If this array is shorter than the *to* array, all the following subtransactions will default to a value of 0
> * ***bytes\[]*****&#x20;callData** - an array of call data to include in the subtransactions, where the index corresponds to the subtransaction of the same index in the *to* array. If this array is shorter than the *to* array, all of the following subtransactions will include no call data
> * ***uint64\[]*****&#x20;gasLimit** - an array of gas limits in the subtransactions, where the index corresponds to the subtransaction of the same index in the *to* array. Values of 0 are interpreted as unlimited and will have all remaining gas of the batch transaction forwarded. If this array is shorter than the *to* array, all of the following subtransactions will have all remaining gas forwarded

* Address: The target of each subcall. For instance, a smart contract to interact with.
* Value: native token (GLMR) to send with the transaction. If none, write 0.
* callData: The encoded data of the transaction to execute, similar to Squid Hook requirements
* gasLimit: Max gas to be used per subcall. 0 is unlimited.


---

# 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://jungle-toolkit.gitbook.io/evm-xcm-jungle-toolkit/build-batches-on-source-and-destination-chains-using-squid-and-batch-precompile/understanding-the-batch-precompile.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.
