4. Use Thanos SDK to interact between two networks
CrossChainMessenger in Thanos SDK is designed to facilitate cross-chain communication between Ethereum and the L2 built by Thanos Stack. It allows sending messages and executes transactions between L1 and L2, simplifying moving assets between them.
The CrossChainMessenger constructor is:
To deposit ETH, we can initialize the CrossChainMessenger instance:
We already defined the known network on the CrossChainMessenger class. But if your network is custom, you can initialize the CrossChainMessenger instance with the custom opts.contracts .
5. Setup the token contracts
First, you must import the @tokamak-network/core-utils package.
Then, set up the ETH contract on L2.
6. Deposit tokens
You can use the L1 standard bridge contract to bridge the ETH from L1 to L2. You will receive the same amount in the L2 after successfully depositing it.
6.1. Deposit tokens
Predefine your deposit amount.
Execute your deposit transaction by using the bridgeETH function.
6.2. Wait for the deposit to be relayed
We can wait for the deposit transaction until it’s relayed on the L2 chain by using the waitForMessageStatus function.
6.3. Verify your balances
7. Withdraw tokens
To withdraw ETH from L2 to L1, you can use the L2 standard bridge contract.
Predefine your withdrawal amount.
7.1. Initialize your withdrawal transaction
To withdraw your tokens on L2, you can use the withdrawETH function.
7.2. Wait for your withdrawal transaction until it is ready to prove
You must prove the withdrawal transaction on L1. So, you need to wait until the withdrawal is ready to prove.
7.3. Prove the withdrawal transaction on L1
When your withdrawal transaction is ready to be proven, you must send the proven transaction on L1 to prove that the transaction happened on L2.
7.4. Wait for your withdrawal transaction until it is ready to finalize
The final step is to finalize your withdrawal transaction on L1. This can only happen after the fault-proof period has elapsed.
💡
7.5. Finalize your withdrawal transaction
Once the withdrawal is ready to be relayed, you can finally complete the withdrawal process.
let l1ETHBalance = await l1Signer.getBalance()
let l2ETHBalance = await ethContractOnL2.balanceOf(l2Signer.address)
console.log(`ETH Token on L1:${l1ETHBalance} \\n
ETH Token on L2: ${l2ETHBalance}`);
let l1ETHBalance = await l1Signer.getBalance()
let l2ETHBalance = await ethContractOnL2.balanceOf(l2Signer.address)
console.log(`ETH Token on L1:${l1ETHBalance} \\n
ETH Token on L2: ${l2ETHBalance}`);