Funds that are available on Matic chain can be withdrawn back to the Ethereum Network.
In Matic, withdrawing is a 3 step process where:
- Withdrawal of funds is initiated from Matic Network. A checkpoint interval of 5 mins is set, where all the blocks on the Matic block layer are validated since the last checkpoint.
- Once the checkpoint is submitted to the mainchain Ethereum contract, an NFT Exit (ERC721) token is created of equivalent value. Users need to wait for a 7 day challenge period (For testnets wait for ~5 minutes for)
- Once the challenge period is complete, the withdrawn funds can be claimed back to your Ethereum acccount from the mainchain contract using a process-exit procedure.
For now, just go with the fact that the challenge period for withdrawals is an important part of the Plasma framework to ensure security of your transactions. Later, once you get to know the system better, the reason for the 7-day withdrawal window will become clear to you.
Just for reference, there will be an active exit market, which will allow trading of exit tokens (ERC721), thereby leading to faster withdrawals — but that is an article for another day.
To keep the withdrawal process easier for now on the Matic Testnet, we have not enforced the 7-day withdrawal process. This means while going through this tutorial and developing apps on the testnet, for now, you will get the withdrawn funds immediately after you initiate the
Now, depending upon your asset, add the following code:
NOTE: Wait for next checkpoint, which will take approximately 5-10 mins. Save the transaction hash which will be the input for next step which is the confirm withdraw step.
The code for process exit remains common for ERC20 and ERC721 tokens except for the value of
Note: A checkpoint, which is a representation of all transactions happening on the Matic Network to the Ethereum chain every ~5 minutes, is submitted to the mainchain Ethereum contract.
We will now initiate the Withdraw process.
We currently have
9.900 TEST tokens at our address on Matic —
We will withdraw
1 TEST from the Matic Account.
To initiate the withdraw we will run
$ node initiate-withdraw-ERC20.js.
Once this process is initiated, you will receive the transaction hash. The transaction hash will be used as input to run the next step i.e. confirm withdraw process.
I’ll add the transaction hash to the code —
0x1b12ae634c7538adfcbddd5028ea47aa97fd8d07c0e3aeffd0caa2fff80cc365. Note that in your case, this transaction hash will be different.
Once the initiate process is complete, we will wait for ~5 minutes, before running the second script
$ node confirm-withdraw.js.
To verify, we will also check the account balances on Metamask.
The balance on Account 1 on Matic Network now shows
8.900 TEST Tokens.
Now, in order to claim your funds after the challenge period is complete, you will need to run the
So let's run
Once this is complete, you will see the funds in your Görli account.
So that’s it folks! You have withdrawn your funds successfuly and gotten to the end of this tutorial :). The example code for performing deposit,transfer and withdraw of tokens from ethereum to matic can be found in this github repository
Hope you have understood now that interacting with the Matic Network is quite easy. We will dive deeper and explore advanced interactions with Matic in later posts.
Similarly, as an exercise you can Deposit, transfer and withdraw ERC721 and Ether using Matic.js following the same steps as above.
Feel free to reach out to us at https://forum.matic.network/ in case you face any issues.