Bridging

Use ZKsync CLI to bridge between L1 and L2 chains

The ZKsync CLI provides bridging commands to deposit and withdraw ETH and ERC20 tokens between L1 and L2 chains.

Deposit

To deposit ETH from L1 to L2, use the bridge sub-command. You can pass all the required options as flags for the command, otherwise the CLI will prompt for the required values.

zksync-cli bridge deposit

The CLI requires the L2 chain, the amount to deposit, the private key and the recipient address on the L2. The recipient address will default to the public address of the private key you provide.

? Chain to use ZKsync Sepolia Testnet
? Amount to deposit 0.005
? Private key of the sender [hidden]
? Recipient address on L2 0xfAa77e3314c82cD5097B80Ab42C6A3749f33dEE6

A deposit summary will display and the transaction will take a moment to process before it further displays the successful transaction details.

Deposit:
 From: 0xfAa77e3314c82cD5097B80Ab42C6A3749f33dEE6 (Ethereum Sepolia Testnet)
 To: 0xfAa77e3314c82cD5097B80Ab42C6A3749f33dEE6 (ZKsync Sepolia Testnet)
 Amount: 0.005 ETH (Ether)

Deposit sent:
 Transaction hash: 0x68a0f2b08ca053faa37c1ea51a562ac7a119271555fc829e6db74d82d2f7a2b7
 Transaction link: https://sepolia.etherscan.io/tx/0x68a0f2b08ca053faa37c1ea51a562ac7a119271555fc829e6db74d82d2f7a2b7

Sender L1 balance after transaction: 0.041260124570176254 ETH (Ether)

Withdraw

You can use the withdraw sub-command to transfer ETH or ERC20 tokens from L2 to L1.

zksync-cli bridge withdraw

The CLI requires the L2 chain, the amount to deposit, the private key and the recipient address on the L1. The recipient address will default to the public address of the private key you provide.

? Chain to use ZKsync Sepolia Testnet
? Amount to withdraw 0.005
? Private key of the sender [hidden]
? Recipient address on L1 0xfAa77e3314c82cD5097B80Ab42C6A3749f33dEE6

A deposit summary will display and the transaction will take a moment to process before it further displays the successful transaction details.

Withdraw:
 From: 0xfAa77e3314c82cD5097B80Ab42C6A3749f33dEE6 (ZKsync Sepolia Testnet)
 To: 0xfAa77e3314c82cD5097B80Ab42C6A3749f33dEE6 (Ethereum Sepolia Testnet)
 Amount: 0.005 ETH (Ether)

Withdraw sent:
 Transaction hash: 0xa50f8c1ffd0d7cdbd7a623f8dd63ee1731e6c4e393d8b7ed954bb19285b369f3
 Transaction link: https://sepolia.explorer.zksync.io/tx/0xa50f8c1ffd0d7cdbd7a623f8dd63ee1731e6c4e393d8b7ed954bb19285b369f3

Sender L2 balance after transaction: 0.1003136843418423 ETH (Ether)

Withdraw-Finalize

Any withdrawals may require a withdraw-finalize dependent upon the rules of the L2. ZKsync Era has a 24 hour delay before you can finalize your withdrawal on L1. The withdraw-finalize sub-command finalizes the transaction with the private key of the sender.

zksync-cli bridge withdraw-finalize

The CLI asks for the chain, the L2 withdrawal transaction hash and the private key of the sender to initiate the finalization of the withdrawal.

? Chain to use ZKsync Sepolia Testnet
? L2 withdrawal transaction hash to finalize 0xa50f8c1ffd0d7cdbd7a623f8dd63ee1731e6c4e393d8b7ed954bb19285b369f3
? Private key of the sender [hidden]

The CLI then displays the details of the withdrawal to finalize and check on the status of the transaction.

Withdraw finalize:
 From chain: ZKsync Sepolia Testnet
 To chain: Ethereum Sepolia Testnet
 Withdrawal transaction (L2): 0xa50f8c1ffd0d7cdbd7a623f8dd63ee1731e6c4e393d8b7ed954bb19285b369f3
 Finalizer address (L1): 0xfAa77e3314c82cD5097B80Ab42C6A3749f33dEE6

Checking status of the transaction...

If the transaction is available to finalize, it will display a successful message.

Transaction is ready to be finalized

Sending finalization transaction...

Withdrawal finalized:
 Finalization transaction hash: 0x9877c291dbfa232d01ac1daa7d72cbda727ccc0d893f5851464d20db9bd0db2a
 Transaction link: https://sepolia.etherscan.io/tx/0x9877c291dbfa232d01ac1daa7d72cbda727ccc0d893f5851464d20db9bd0db2a

Waiting for finalization transaction to be mined...
 Finalization transaction was mined in block 6375446

Sender L1 balance after transaction: 0.04570351455452712 ETH (Ether)

If the transaction is still waiting to be processed fully from L2 to L1, an error will display.

Checking status of the transaction...
Transaction is still being processed on ZKsync Sepolia Testnet, please try again when the ethExecuteTxHash has been computed
L2 Transaction Details: {
  "ethCommitTxHash": null,
  "ethExecuteTxHash": null,
  "ethProveTxHash": null,
  "fee": "0xa77644aa700",
  "gasPerPubdata": "0xc350",
  "initiatorAddress": "0xfaa77e3314c82cd5097b80ab42c6a3749f33dee6",
  "isL1Originated": false,
  "receivedAt": "2024-07-24T18:06:57.307Z",
  "status": "included"
}

Made with ❤️ by the ZKsync Community