Request Zone Withdrawal
zone.requestWithdrawal
Requests a withdrawal from a zone to the parent Tempo chain.
Batches an approval and a ZoneOutbox withdrawal request into a single transaction.
Usage
import { } from './zones.config'
const { , } = await ..({
: 100_000_000n,
: '0x20c0000000000000000000000000000000000001',
})
.('Transaction hash:', .)
Transaction hash: 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef.('Withdrawal sender tag:', )Withdrawal sender tag: 0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890import { , } from 'viem/tempo'
import { , } from 'viem/tempo/zones'
export const = .({
: .('0x...'),
: (7),
: (),
})Asynchronous Usage
The example above uses a *Sync variant of the action, that will wait for the transaction to be included before returning.
If you are optimizing for performance, you should use the non-sync zone.requestWithdrawal action and wait for inclusion manually:
import { } from './zones.config'
const = await ..({
: 100_000_000n,
: '0x20c0000000000000000000000000000000000001',
})
const = await ..({ }).Prepared Usage
Use Actions.zone.requestWithdrawal.prepare to populate and inspect the Zone transaction request without broadcasting. It returns the populated request, normalized withdrawal fields, and maxFee, rounded up into fee-token base units using Tempo's gas-price conversion.
Use zone.getWithdrawalFee separately to inspect the protocol withdrawal fee.
import { } from 'viem/tempo'
import { } from './zones.config'
const = await ...(, {
: 100_000_000n,
: 10_000_000n,
: '0x20c0000000000000000000000000000000000001',
})
.('Maximum fee:', .)
.('Gas limit:', ..)
.('Calls:', ..)The prepare helper returns:
type PreparedWithdrawal = {
amount: bigint
callbackGas: bigint
data: Hex
fallbackRecipient: Address
maxFee: bigint
memo: Hex
request: TransactionRequest
to: Address
token: Address
}Recipes
Pay a Vendor Directly on Tempo
Pass to to settle an invoice straight from the zone to a vendor's Mainnet address, with a memo carrying the invoice reference for reconciliation.
import { } from 'viem/utils'
import { } from './zones.config'
const { } = await ..({
: 4_500_000_000n,
: .('inv_2049', { : 32 }),
: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
: '0x20c0000000000000000000000000000000000001',
})import { , } from 'viem/tempo'
import { , } from 'viem/tempo/zones'
export const = .({
: .('0x...'),
: (7),
: (),
})Withdraw into a Contract with a Callback
Reserve callbackGas and pass data when the Mainnet recipient is a contract, and set fallbackRecipient so funds recover to your treasury if the callback fails.
import { } from './zones.config'
const { } = await ..({
: 100_000_000n,
: 100_000n,
: '0xd0e30db0',
: '0x8ba1f109551bD432803012645Ac136ddd64DBA72',
: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
: '0x20c0000000000000000000000000000000000001',
})import { , } from 'viem/tempo'
import { , } from 'viem/tempo/zones'
export const = .({
: .('0x...'),
: (7),
: (),
})Return Value
type ReturnType = {
/** Transaction receipt. */
receipt: TransactionReceipt
/** Sender tag identifying the parent-chain WithdrawalProcessed event. */
senderTag: Hex
}The transaction receipt and sender tag for the parent-chain WithdrawalProcessed event. The non-sync
zone.requestWithdrawal action returns the transaction hash.
Parameters
amount
- Type:
bigint
Amount of tokens to withdraw.
callbackGas
- Type:
bigint - Default:
0n
Gas limit reserved for the withdrawal callback on the parent chain.
data
- Type:
Hex
Callback data for the recipient on the parent chain.
fallbackRecipient
- Type:
Address - Default:
to
Fallback address if the callback fails.
memo
- Type:
Hex
Withdrawal memo.
to
- Type:
Address - Default:
account.address
Recipient address on the parent Tempo chain.
token
- Type:
Address
Token address to withdraw.
For this action, the inherited gas parameter defaults to 10_000_000n. It limits the Zone
transaction and is independent of callbackGas.
account (optional)
- Type:
Account | Address
Account that will be used to send the transaction.
feePayer (optional)
- Type:
Account | boolean
Fee payer for the transaction (TIP-1 gas sponsorship).
Pass true to defer the fee token to an external fee payer (e.g. a relay), or a local Account to co-sign the transaction as the fee payer.
feeToken (optional)
- Type:
Address | bigint
Fee token for the transaction.
Can be an unpaused USD-denominated TIP-20 token address or ID.
gas (optional)
- Type:
bigint
Gas limit for the transaction.
keyAuthorization (optional)
- Type:
KeyAuthorization
Signed key authorization to include with the transaction, authorizing an access key to act for the sending account.
maxFeePerGas (optional)
- Type:
bigint
Max fee per gas for the transaction.
maxPriorityFeePerGas (optional)
- Type:
bigint
Max priority fee per gas for the transaction.
nonce (optional)
- Type:
number
Nonce for the transaction.
nonceKey (optional)
- Type:
'expiring' | 'random' | bigint
Nonce key for the transaction (TIP-1009 2D nonces).
Use 'expiring' to select an expiring nonce, which enables concurrent transaction submission without nonce ordering. Use 'random' to select a random key.
throwOnReceiptRevert (optional)
- Type:
boolean - Default:
true
Whether a Sync action throws when the receipt reports a revert.
validAfter (optional)
- Type:
number
Unix timestamp after which the transaction can be included.
validBefore (optional)
- Type:
number
Unix timestamp before which the transaction must be included.