initiateETHWithdrawal
Initiates a ETH withdrawal on an L2 to the L1.
Internally performs a contract write to the withdraw
function on the Mantle L2StandardBridge predeploy contract.
Usage
example.ts
import { mantle } from '@mantleio/viem'
import { account, walletClientL2 } from './config'
// User might need to update allowance for first time deposit.
const approvalHash = await walletClientL2.writeContract({
account,
address: "0xdeaddeaddeaddeaddeaddeaddeaddeaddead1111", //L2 ETH
abi:erc20Abi,
functionName:'approve',
args:[mantle.contracts.l2StandardBridge.address,parseEther('1')]
})
const hash = await walletClientL2.initiateETHWithdrawal({
account,
request: {
amount: parseEther('1'),
},
})
Returns
The L2 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 client.initiateETHWithdrawal({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
request: {
amount: parseEther('1'),
},
targetChain: mantle,
})
args.amount
- Type:
bigint
Amount in wei to ETH withdrawal from the L2 to the L1. Debited from the caller's L2 balance.
const hash = await client.initiateETHWithdrawal({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
request: {
amount: parseEther('1'),
},
})
args.to (optional)
- Type:
Address
L1 Transaction recipient.
const hash = await client.initiateETHWithdrawal({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
request: {
amount: parseEther('1'),
to: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
},
targetChain: mantle,
})
chain (optional)
- Type:
Chain
- Default:
client.chain
The L2 chain. If there is a mismatch between the wallet's current chain & this chain, an error will be thrown.
import { mantle } from '@mantleio/viem/chains'
const hash = await client.initiateETHWithdrawal({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
request: {
amount: parseEther('1'),
},
chain: mantle,
})
maxFeePerGas (optional)
- Type:
bigint
Total fee per gas (in wei), inclusive of maxPriorityFeePerGas
.
const hash = await client.initiateETHWithdrawal({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
request: {
amount: parseEther('1'),
},
maxFeePerGas: parseGwei('20'),
})
maxPriorityFeePerGas (optional)
- Type:
bigint
Max priority fee per gas (in wei). Only applies to EIP-1559 Transactions
const hash = await client.initiateETHWithdrawal({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
request: {
amount: parseEther('1'),
},
maxFeePerGas: parseGwei('20'),
maxPriorityFeePerGas: parseGwei('2'),
})
nonce (optional)
- Type:
number
Unique number identifying this transaction.
const hash = await client.initiateETHWithdrawal({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
request: {
amount: parseEther('1'),
},
nonce: 69,
})