When Ethereum Has Too Expensive Transaction Costs – Future for Layer2?

Tram Ho

With the rapid development of Blockchain, ETH seems to be overloaded and as a result, the cost of Gas has reached 1000Gwei, the fee to create complicated transactions is approximately $ 500. And a lifesaver for Defi products on ETH is Layer2, and in this mission Matic is showing its ability very well.

Introduce

Matic was built with the intent of supporting Ethereum, not being an Ethereum killer. Matic supports the mapping of tokens between Ethereum and Matic and has built bridges between them. One of the typical products that is Aavegotchi application has had to delay the release date due to the terrible cost on Ethereum, if you want to read more about this application you can see through my article. :

In this article, I will guide you to build Dapps on Layer2

Practice

In this article, I will guide you from how to configure metamask to interact with Matic, Deploy a Dapp on Matic and introduce through the exchange of information between Layer 1 and Layer 2.

Config metamask

We will need mainnet when using dapps on Matic or testnet when building and testing dapps. So I will guide you to configure both networks:

Mainnet

Repair using rpc: https://rpc-mainnet.maticvigil.com/

Testnet

Using rpc: https://rpc-mumbai.maticvigil.com/

Deploy contract

In this example, I will use Remix to deploy a test contract on Layer2 Matic, and there will also be some things to note:

  • Contract is written in solidity so you also need a little programming knowledge to understand what the contract is doing
  • The Metamask wallet was configured in the above steps and had a bit of Matic to pay the deploy fee, you can faucet here: https://faUCet.matic.network/

Now go straight to remix ( https://remix.ethereum.org/ ) and let’s deploy:

We will deploy the contract directly above, I will use the mainnet to deploy because the fee to deploy is completely cheap:

Ok. So the deploying contract on this layer2 is no different from the Ethereum side, only the fee is greatly reduced, you can try through two functions call and send immediately.

Ethereum <-> Polygon

Polygon (Matic) in addition to improving the speed and fee of transactions compared to ETH, what makes Matic emerging is the large support scale for ETH and of course this bridge is really good.

POS and Plasma

These bridges are built with the following criteria:

  • Tokens are pegged 1: 1, so it is absolutely safe to not change the total supply of tokens
  • When transferring tokens from Polygon back to ETH, the tokens on the Polygon side will be burned and the tokens on the Ethereum side will be unlocked

There are currently 2 bridges to convert a cross-chain token from eth to polygon and vice versa:

  • PoS
  • Plasma

And here is an overview comparison between these two bridges:

PoS Bridge

Recently, applications are being encouraged to use PoS Bridge, so this article I will focus on PoS Bridge more.

Plasma Bridges are built to improve security and PoS Bridges are for speed, so they will always exist together depending on the purpose of the users.

In this bridge we will need 2 connectors, Root Token and Child Token . These are the 2 ends so we can map between each other. Currently at the time of the article being published, this layer2 is supporting 3 tokens: ERC20 , ERC721 , ERC1155.

The registration of these 2 bridges we will register through here: https://mapper.matic.today/

Once registered, we can use the matic.js SDK to interact with the contract or also interact with the contract.

One complete conversion step can be explained:

  1. Owners of assets ( ERC20, ERC721, ERC1155 ) will approve for the Predicate Contract to have the right to use the amount of tokens you want to transfer to Polygon (this contract will later be responsible for locking those tokens)
  2. After approve successfully, the RootChainManager contract will call the deposit function and will also trigger the Polygon side for the ChildChainManager contract.
  3. Send information between the two chains through events, you can read more carefully here: https://docs.matic.network/docs/contribute/state-sync/
  4. Contract ChildChainManager calls the deposit function to mint the corresponding amount of tokens that are locked on Polygon side (Only the ChildChainManager contract has the right to call this function)
  5. At this step, on Polygon side you have received the corresponding token and can trade on Polygon

To bring assets back to Ethereum we will have 2 steps:

  1. Token on the Polygon side will be burned (It will take about 10 – 30 minutes to be able to complete the transaction burn and submit to the Ethereum side, this transaction burn will be validated by validators using the PoS mechanism). After completing this transaction, it will be submitted to RootChainManager on Ethereum side
  2. Contract Predicate after receiving proof from RootChainManager will unlock the number of tokens that we previously locked when moving from Ethereum to.

Conclude

In this article, Plolygon is getting stronger as it has improved well for Ethereum and is also gradually catching the NFT trend as NFT Dapps continuously climb to Polygon because of Ethereum’s exorbitant gas price. Let’s expect Polygon to soon build a bridge so that User can deposit or withdraw from Mainnet Polygon to Binance app.

See you in the next article, I will more clearly demonstrate the direct manipulation of the contract when transferring information between 2 layers.

Refer

Official docs: https://docs.matic.network/

Share the news now

Source : Viblo