# Batching Transactions (/smart-accounts/batch-transactions)

> For the complete documentation index, see [llms.txt](/llms.txt)



<Callout type="info">
  Impatient?  Check out [complete examples here](https://github.com/zerodevapp/zerodev-examples/tree/main/batch-transactions).
</Callout>

Batching is very useful for simplifying Web3 interactions for your users.  For instance, instead of doing `approve()` followed by `transfer()`, your user can do both in one transaction.

Batching transactions has a number of important benefits:

<Cards>
  <Card icon="transaction" title="One transaction">
    Your user waits for only 1 transaction instead of multiple.
  </Card>

  <Card icon="gas" title="Less gas">
    Your user pays less gas.
  </Card>

  <Card icon="key" title="Atomicity">
    If any transaction in the batch reverts, the entire batch reverts. This ensures that your user won't be stuck in an inconsistent state.
  </Card>
</Cards>

## API [#api]

There are two ways to send batched transactions.  `sendTransaction` is a simple API that's good enough for most use cases.  If you need fine-grained control over your UserOp, you can use `sendUserOperation`.

### `sendTransaction` [#sendtransaction]

```typescript
const txHash = await kernelClient.sendTransaction({
  calls: [
    {
      to: "0xADDRESS",
      value: value,
      data: "0xDATA",
    },
    {
      to: "0xADDRESS",
      value: value,
      data: "0xDATA",
    },
  ],
})
```

### `sendUserOperation` [#senduseroperation]

You can learn more about the `sendUserOperation` API [here](/smart-accounts/send-transactions#sending-raw-userops).

To send a UserOp with batching, simply pass an array of calls into `encodeCalls`.

```typescript
const userOpHash = await kernelClient.sendUserOperation({
        callData: account.encodeCalls([
          {
            to,
            value,
            data,
          },
          {
            to,
            value,
            data,
          },
        ]),
        // other UserOp params
})
```

### Execute a batch without reverting if some of the calls fail [#execute-a-batch-without-reverting-if-some-of-the-calls-fail]

By default, batching is atomic -- if any of the calls fails, the whole batch will fail.

If you want to execute the batch such that even if some of the calls fail, the other calls will still execute, you can execute it with the `TRY` mode:

```typescript
import {
    EXEC_TYPE,
} from "@zerodev/sdk/constants"

const userOpHash = await kernelClient.sendUserOperation({
    callData: await kernelClient.account.encodeCalls([
        // ... your calls
    ], "call", EXEC_TYPE.TRY_EXEC),
})
```
