# Batch Calls

## Overview

Tempo Transactions can bundle multiple operations into a single atomic transaction using the
`calls` property. The calls execute together under one signature, and if any call reverts, the
entire transaction reverts. This is useful for flows like approve-then-transfer without the risk
of a partially applied state.

[See the Tempo Transactions specification](https://docs.tempo.xyz/protocol/transactions/spec-tempo-transaction)

## Recipes

These recipes assume you have [set up a Tempo client](/tempo).

### Batch Raw Calls

Pass an array of `{ to, data }` calls to
[`sendTransactionSync`](/docs/actions/wallet/sendTransactionSync).

:::code-group
```ts twoslash [example.ts]
import { client } from './viem.config'

const receipt = await client.sendTransactionSync({
  calls: [ // [!code focus]
    { // [!code focus]
      data: '0xcafebabe00000000000000000000000000000001', // [!code focus]
      to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef', // [!code focus]
    }, // [!code focus]
    { // [!code focus]
      data: '0xdeadbeef00000000000000000000000000000002', // [!code focus]
      to: '0xfeedfacefeedfacefeedfacefeedfacefeedface', // [!code focus]
    }, // [!code focus]
  ], // [!code focus]
})
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
// [!include ~/snippets/tempo/viem.config.ts:setup]
```
:::

### Batch Tempo Actions

Tempo Actions expose a `.call` helper that returns a call you can drop into `calls`. This lets
you batch high-level actions, such as approving and transferring a token in one transaction.

:::code-group
```ts twoslash [example.ts]
import { Actions } from 'viem/tempo'
import { client } from './viem.config'

const usd = '0x20c0000000000000000000000000000000000001'

const receipt = await client.sendTransactionSync({
  calls: [
    Actions.token.approve.call({ // [!code focus]
      amount: 100n, // [!code focus]
      spender: '0xcafebabecafebabecafebabecafebabecafebabe', // [!code focus]
      token: usd, // [!code focus]
    }), // [!code focus]
    Actions.token.transfer.call({ // [!code focus]
      amount: 100n, // [!code focus]
      to: '0xcafebabecafebabecafebabecafebabecafebabe', // [!code focus]
      token: usd, // [!code focus]
    }), // [!code focus]
  ],
})
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
// [!include ~/snippets/tempo/viem.config.ts:setup]
```
:::

## Best Practices

### Batches Are Atomic

All calls in a batch succeed or fail together. If any call reverts, the whole transaction
reverts and no state changes are applied. Order the calls so dependencies (e.g. an approval)
come before the operations that rely on them.

## See More

<Cards>
  <Card icon="lucide:send" title="Tempo Transactions" description="Send Tempo Transactions and discover the payment features they unlock." to="/tempo/transactions" />

  <Card icon="lucide:coins" title="Tokens" description="Create, mint, transfer, and manage TIP-20 tokens to batch together." to="/tempo/guides/create-token" />

  <Card icon="lucide:book-open" title="Tempo Docs: Batch Transactions" description="The full guide to batching operations into one Tempo Transaction." to="https://docs.tempo.xyz/guide/use-accounts/batch-transactions" />
</Cards>
