withdraw
Initiates the withdrawal process which withdraws ETH or any ERC20 token from the associated account on L2 network to the target account on L1 network.
Usage
import { account, walletClient } from './config'
import { legacyEthAddress } from 'viem/zksync'
 
const hash = await walletClient.withdraw({
  account,
  amount: 1_000_000_000_000_000_000n,
  token: legacyEthAddress,
})Account Hoisting
If you do not wish to pass an account to every withdraw, you can also hoist the Account on the Wallet Client (see config.ts).
import { walletClient } from './config'
import { legacyEthAddress } from 'viem/zksync'
 
const hash = await walletClient.withdraw({ 
  amount: 1_000_000_000_000_000_000n,
  token: legacyEthAddress,  
})
// '0x...'Returns
The Transaction hash.
Parameters
account
- Type: Account | Address
The Account to send the transaction from.
Accepts a JSON-RPC Account or Local Account (Private Key, etc).
const hash = await walletClient.withdraw({
  account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', 
  amount: 1_000_000_000_000_000_000n,
  token: legacyEthAddress,
})amount
- Type: bigint
The amount of the token to withdraw.
const hash = await walletClient.withdraw({
  account,
  amount: 1_000_000_000_000_000_000n, 
  token: legacyEthAddress,
})token
- Type: Address
The address of the token on L2.
const hash = await walletClient.withdraw({
  account,
  amount: 1_000_000_000_000_000_000n,
  token: legacyEthAddress, 
})bridgeAddress (optional)
- Type: Address
The address of the bridge contract to be used. By default, uses shared bridge.
const address = await walletClient.withdraw({
  account,
  amount: 1_000_000_000_000_000_000n,
  token: legacyEthAddress,
  bridgeAddress: '0xf8c919286126ccf2e8abc362a15158a461429c82'
})chain (optional)
- Type: Chain
- Default: walletClient.chain
The target chain. If there is a mismatch between the wallet's current chain & the target chain, an error will be thrown.
The chain is also used to infer its request type.
import { zksync } from 'viem/chains'
 
const hash = await walletClient.withdraw({
  chain: zksync, 
  account,
  amount: 1_000_000_000_000_000_000n,
  token: legacyEthAddress,
})gasPerPubdata (optional)
- Type: bigint
The amount of gas for publishing one byte of data on Ethereum.
const hash = await walletClient.withdraw({
  account,
  amount: 1_000_000_000_000_000_000n,
  token: legacyEthAddress,
  gasPerPubdata: 50000, 
})gasPrice (optional)
- Type: bigint
The price (in wei) to pay per gas. Only applies to Legacy Transactions.
const hash = await walletClient.withdraw({
  account,
  amount: 1_000_000_000_000_000_000n,
  token: legacyEthAddress,
  gasPrice: parseGwei('20'), 
})maxFeePerGas (optional)
- Type: bigint
Total fee per gas (in wei), inclusive of maxPriorityFeePerGas. Only applies to EIP-1559 Transactions
const hash = await walletClient.withdraw({
  account,
  amount: 1_000_000_000_000_000_000n,
  token: legacyEthAddress,
  maxFeePerGas: parseGwei('20'),  
})maxPriorityFeePerGas (optional)
- Type: bigint
Max priority fee per gas (in wei). Only applies to EIP-1559 Transactions
const hash = await walletClient.withdraw({
  account, 
  amount: 1_000_000_000_000_000_000n,
  token: legacyEthAddress,
  maxFeePerGas: parseGwei('20'),
  maxPriorityFeePerGas: parseGwei('2'), 
})nonce (optional)
- Type: number
Unique number identifying this transaction.
const hash = await walletClient.withdraw({
  account,
  amount: 1_000_000_000_000_000_000n,
  token: legacyEthAddress,
  nonce: 69
})paymaster (optional)
- Type: Account | Address
Address of the paymaster account that will pay the fees. The paymasterInput field is required with this one.
const hash = await walletClient.withdraw({
  account,
  amount: 1_000_000_000_000_000_000n,
  token: legacyEthAddress,
  paymaster: '0x4B5DF730c2e6b28E17013A1485E5d9BC41Efe021', 
  paymasterInput: '0x8c5a...'
})paymasterInput (optional)
- Type: 0x${string}
Input data to the paymaster. The paymaster field is required with this one.
const hash = await walletClient.withdraw({
  account,
  amount: 1_000_000_000_000_000_000n,
  token: legacyEthAddress,
  paymaster: '0x4B5DF730c2e6b28E17013A1485E5d9BC41Efe021', 
  paymasterInput: '0x8c5a...'
})to (optional)
- Type: Address
The address of the recipient on L1. Defaults to the sender address.
const hash = await walletClient.withdraw({
  account,
  amount: 1_000_000_000_000_000_000n,
  token: legacyEthAddress,
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', 
})
