# Send & Settle Vouchers

## Overview

A voucher is a signed, off-chain promise from the payer that the channel has paid a given cumulative
amount. The payer signs a new voucher for each payment with a higher cumulative amount, and the payee
can settle the latest one onchain whenever they want. Because vouchers are off-chain, payments are
instant and free until settlement.

[See the Payment Channels guide](https://docs.tempo.xyz/guide/machine-payments/pay-as-you-go)

## Recipes

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

### Sign a Voucher

As the payer, sign a voucher for a cumulative amount with
[`channel.signVoucher`](/tempo/actions/channel.signVoucher). The cumulative amount is the total paid
over the life of the channel, not the per-payment delta.

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

const signature = await client.channel.signVoucher({
  channel,
  cumulativeAmount: parseUnits('40', 6),
})
```

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

// [!include ~/snippets/tempo/viem.config.ts:channel]
```
:::

### Settle a Voucher

As the payee, settle a voucher onchain with [`channel.settleSync`](/tempo/actions/channel.settle) to
capture the paid amount up to that point.

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

const result = await client.channel.settleSync({
  cumulativeAmount: parseUnits('40', 6),
  channel,
  signature: '0x...',
})
```

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

// [!include ~/snippets/tempo/viem.config.ts:channel]
```
:::

## Best Practices

### Always Sign Cumulative Amounts

Each voucher carries the running total paid, not the increment. Sign a strictly increasing cumulative
amount per payment so the payee can always settle the latest voucher and ignore older ones.

### Keep Only the Latest Voucher

The payee only needs the highest-amount voucher to settle, since it supersedes all earlier ones.
Storing just the latest signed voucher keeps state minimal and avoids accidental double counting.

### Settle Before the Deposit Is Exhausted

A voucher can only be settled up to the channel's deposit. Watch the cumulative amount against the
deposit and either settle and top up, or ask the payer to top up, before the channel runs dry.

## See More

<Cards>
  <Card icon="lucide:plug" title="Open & Fund a Channel" description="Open and fund the channel that backs these vouchers." to="/tempo/guides/payment-channels/open" />

  <Card icon="lucide:circle-x" title="Close & Withdraw" description="Reconcile the final balance and close the channel." to="/tempo/guides/payment-channels/close" />

  <Card icon="lucide:square-function" title="channel.settle" description="Settle a signed voucher onchain as the payee." to="/tempo/actions/channel.settle" />

  <Card icon="lucide:book-open" title="Tempo Docs: Payment Channels" description="How off-chain vouchers and settlement work." to="https://docs.tempo.xyz/guide/machine-payments/pay-as-you-go" />
</Cards>
