# Scheduled Transactions

## Overview

Tempo Transactions can specify a time window during which they are valid for inclusion. By
setting `validAfter` and `validBefore`, you sign a transaction in advance and define the earliest
and latest times it can be included in a block. This is useful for delayed payments and
time-limited authorizations.

[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).

### Schedule a Transaction

Set `validAfter` and `validBefore` (Unix timestamps, in seconds) to define the inclusion window.

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

const receipt = await client.sendTransactionSync({
  data: '0xdeadbeef',
  to: '0xcafebabecafebabecafebabecafebabecafebabe',
  validAfter: Math.floor(Number(new Date('2026-01-01')) / 1000), // [!code focus]
  validBefore: Math.floor(Number(new Date('2026-01-02')) / 1000), // [!code focus]
})
```

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

### Set an Expiry Only

Provide only `validBefore` to create a transaction that must be included before a deadline, or
only `validAfter` to delay one until a start time.

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

const receipt = await client.sendTransactionSync({
  data: '0xdeadbeef',
  to: '0xcafebabecafebabecafebabecafebabecafebabe',
  validBefore: Math.floor(Date.now() / 1000) + 60 * 60, // expires in 1 hour // [!code focus]
})
```

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

## Best Practices

### Use Second-Precision Timestamps

`validAfter` and `validBefore` are Unix timestamps in seconds, not milliseconds. Convert from
JavaScript `Date` (which uses milliseconds) by dividing by `1000` and flooring, as shown above.

## 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:split" title="Send Concurrent Transactions" description="Send transactions in parallel using independent nonce keys." to="/tempo/guides/concurrent-transactions" />

  <Card icon="lucide:book-open" title="Tempo Docs: Transactions" description="The full Tempo Transactions protocol specification." to="https://docs.tempo.xyz/protocol/transactions/spec-tempo-transaction" />
</Cards>
