Skip to content

initiateERC20Withdrawal

Initiates a ERC20 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'
 
const hash = await walletClientL2.initiateERC20Withdrawal({
  account,
  request: {
    l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
    amount: parseEther('1'),
  },
})

Returns

Hash

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.initiateERC20Withdrawal({
  account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', 
  request: {
    l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
    amount: parseEther('1'),
  },
  targetChain: mantle,
})

args.l2Token

  • Type: Address

The L2 token contract address.

const hash = await client.initiateERC20Withdrawal({
  account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
  request: {
    l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828', 
    amount: parseEther('1'),
  },
})

args.amount

  • Type: bigint

Amount in wei to ERC20 withdrawal from the L2 to the L1. Debited from the caller's L2 balance.

const hash = await client.initiateERC20Withdrawal({
  account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
  request: {
    l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
    amount: parseEther('1'), 
  },
})

args.to (optional)

  • Type: Address

L1 Transaction recipient.

const hash = await client.initiateERC20Withdrawal({
  account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
  request: {
    l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
    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.initiateERC20Withdrawal({
  account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
  request: {
    l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
    amount: parseEther('1'),
  },
  chain: mantle, 
})

maxFeePerGas (optional)

  • Type: bigint

Total fee per gas (in wei), inclusive of maxPriorityFeePerGas.

const hash = await client.initiateERC20Withdrawal({
  account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
  request: {
    l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
    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.initiateERC20Withdrawal({
  account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
  request: {
    l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
    amount: parseEther('1'),
  },
  maxFeePerGas: parseGwei('20'),
  maxPriorityFeePerGas: parseGwei('2'), 
})

nonce (optional)

  • Type: number

Unique number identifying this transaction.

const hash = await client.initiateERC20Withdrawal({
  account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
  request: {
    l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
    amount: parseEther('1'),
  },
  nonce: 69, 
})