A bridge is basically a set of contracts that help in moving assets from the root chain to the child chain. There are primarily two bridges to move assets between Ethereum and Matic. First one is the Plasma bridge and the second one is called the PoS Bridge or Proof of Stake bridge. Plasma bridge provides an increased security guarantees due to the Plasma exit mechanism.
However, there are certain restrictions on the child token and there is a 7-day withdrawal period associated with all exits/withdraws from Matic to Ethereum on the Plasma bridge. The PoS Bridge is more flexible and features faster withdrawals.
This tutorial will act as a guide for step-by-step process to understand and use Plasma bridge using Matic JS, which is the easiest way to interact with the Plasma Bridge on Matic Network.
Assets flow in Plasma Bridge
We will be showcasing the flow for asset transfers on the Matic Network in this tutorial and how you can do the same using Matic.js:
- User deposits crypto assets in Matic contract on mainchain
- Once deposited tokens get confirmed on the mainchain, the corresponding tokens will get reflected on the Matic chain
- The user can now transfer tokens to anyone they want instantly with negligible fees. Matic chain has faster blocks (approximately 1 second). That way, the transfer will be done almost instantly.
- Once a user is ready, they can withdraw remaining tokens from the mainchain. Withdrawal of funds is initiated from the Plasma Sidechain. 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 Exit NFT (ERC721) token is created of equivalent value.
- Users need to wait for a 7 day challenge period
- 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.
- User can also get a fast exit via 0x or Dharma (coming soon!)
In order to make any transactions, you will also need some Ether in the test accounts that you will use while following the tutorial. In case you don’t have some ETH on Görli, you can use the faucet links given here — https://goerli-faucet.slock.it/.
Throughout this tutorial, we will be using the ERC20 token
TEST on the Görli network as an example. This is a TEST token. In your DApp, you can replace it with any ERC20 token. To get some Test
TEST tokens on Matic Network, you can access the Matic Faucet.
Note: To use your own tokens for deposits and withdrawals, you’ll have to get the token ‘mapped’. Which essentially means making the contracts on main chain and side chain ‘aware’ of your custom token. Read more about the Mapping process here, or you can submit a mapping request here.
Basic setup for the Metamask Wallet (Optional)
- Create a wallet: If you are new to wallets, then Setup a Metamask Account.
- Configure the Matic testnet: To easily visualise the flow of funds on the Matic Network, it is instructive if you configure the Matic testnet on Metamask.Note that we are using Metamask here solely for visualization purposes. There is no requirement to use Metamask at all for using the Matic Network.
- Create Multiple Accounts: Before starting with the tutorial, go ahead and have 3 Ethereum test accounts ready.
- Configure token on Matic: In order to view the flow of funds easily on the Matic Network using Matic.js, you can configure tokens on Metamask. The
TESTtoken, taken as an example for this tutorial, can be configured in Metamask so as to easily visualise account balances. > Again note this is optional. You can very easily query the token balances and other variables using web3
Originally published @ https://docs.matic.network/docs/develop/ethereum-matic/plasma/getting-started/