# Withdraw from a Zone

## Overview

Funds leave a zone by requesting a withdrawal from inside the zone, which moves the balance back to
your Tempo Mainnet account. A verifiable withdrawal additionally hides the sender behind a
cryptographic commitment that only the recipient can reveal.

[See the Zone Bridging specification](https://docs.tempo.xyz/protocol/zones/bridging)

:::warning
Tempo Zones are in early development and available on Tempo Testnet only. Expect breaking changes and
do not use them in production.
:::

## Recipes

These recipes assume you have [connected to a zone](/tempo/guides/zones/connect).

### Check the Withdrawal Fee

Read the current fee for withdrawing from the zone with
[`zone.getWithdrawalFee`](/tempo/actions/zone.getWithdrawalFee) before requesting a withdrawal.

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

const fee = await client.zone.getWithdrawalFee()
```

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

### Withdraw to Mainnet

Request a withdrawal of a TIP-20 token from the zone back to your Mainnet account with
[`zone.requestWithdrawalSync`](/tempo/actions/zone.requestWithdrawal).

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

const { receipt } = await client.zone.requestWithdrawalSync({
  amount: parseUnits('100', 6),
  token: '0x20c0000000000000000000000000000000000001',
})
```

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

### Make a Verifiable Withdrawal

Hide the sender behind a cryptographic commitment with
[`zone.requestVerifiableWithdrawalSync`](/tempo/actions/zone.requestVerifiableWithdrawal). Generate a
keypair and pass its public key as `revealTo`; the holder of the matching private key can later reveal
the sender.

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

// Generate a keypair for decrypting the sender identity later.
// Store the private key securely, as its holder can reveal the sender.
const { publicKey } = Secp256k1.createKeyPair()
const revealTo = PublicKey.toHex(PublicKey.compress(publicKey))

const { receipt } = await client.zone.requestVerifiableWithdrawalSync({
  amount: parseUnits('100', 6),
  revealTo,
  token: '0x20c0000000000000000000000000000000000001',
})
```

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

## Best Practices

### Budget for the Withdrawal Fee

Read `zone.getWithdrawalFee` before withdrawing and ensure the account has enough balance to cover the
fee on top of the amount. Withdrawals that cannot cover the fee will fail.

### Use Verifiable Withdrawals When the Sender Must Be Private

A plain withdrawal can expose the sender. Use `zone.requestVerifiableWithdrawal` when the sender's
identity must stay private, and share the reveal key only with the intended recipient.

### Store the Reveal Key Securely

For verifiable withdrawals, whoever holds the private key behind `revealTo` can reveal the sender.
Treat it like any other secret and store it where only the intended party can access it.

## See More

<Cards>
  <Card icon="lucide:arrow-down-to-line" title="Deposit to a Zone" description="Move stablecoins from Tempo Mainnet into a zone." to="/tempo/guides/zones/deposit" />

  <Card icon="lucide:plug" title="Connect to a Zone" description="Authenticate a Viem client with a zone before withdrawing." to="/tempo/guides/zones/connect" />

  <Card icon="lucide:square-function" title="zone.requestWithdrawal" description="Request a withdrawal from a zone back to Mainnet." to="/tempo/actions/zone.requestWithdrawal" />

  <Card icon="lucide:book-open" title="Tempo Docs: Zone Bridging" description="How deposits and withdrawals move between Mainnet and zones." to="https://docs.tempo.xyz/protocol/zones/bridging" />
</Cards>
