Bridge the Native Token with the Thanos SDK
This tutorial describes how the Thanos SDK can bridge ERC-20 tokens from L1 to L2. You can look at our example: Github
1. Prerequisite
1.1. Dependencies
1.2. Install packages
To use Thanos SDK, first, you must install the package from NPM.
npm install @tokamak-network/thanos-sdk@latest2. Set Environments
// .env example
PRIVATE_KEY=change_me
L1_RPC_URL=change_me
L2_RPC_URL=change_me
L1_TOKEN=change_me
L2_TOKEN=change_me
NATIVE_TOKEN= The native address on L13. Create providers and wallets
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 the native tokens, You must define nativeTokenAddress when initializing 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
6. Deposit tokens
You can use the L1 standard bridge contract to bridge the native tokens from L1 to L2. You will receive the same amount in the L2 after successfully depositing it.
6.1. Approve the StandardBridge use of your native tokens
6.2. Deposit tokens
Predefine your deposit amount.
Execute your deposit transaction by using the bridgeNativeToken function.
6.3. 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.4. Verify your balances
7. Withdraw tokens
To withdraw the native tokens 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 withdrawNativeToken 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. On Thanos Sepolia, the period is 24 mins.
💡
7.5. Finalize your withdrawal transaction
Once the withdrawal is ready to be relayed, you can finally complete the withdrawal process.
7.6. Wait until your withdrawal is relayed
7.7. Verify your balances
Last updated
