Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learn Ethereum

You're reading from   Learn Ethereum A practical guide to help developers set up and run decentralized applications with Ethereum 2.0

Arrow left icon
Product type Paperback
Published in Aug 2023
Publisher Packt
ISBN-13 9781804616512
Length 814 pages
Edition 2nd Edition
Languages
Concepts
Arrow right icon
Authors (3):
Arrow left icon
Dongying Song Dongying Song
Author Profile Icon Dongying Song
Dongying Song
Zhihong Zou Zhihong Zou
Author Profile Icon Zhihong Zou
Zhihong Zou
Xun (Brian) Wu Xun (Brian) Wu
Author Profile Icon Xun (Brian) Wu
Xun (Brian) Wu
Arrow right icon
View More author details
Toc

Table of Contents (24) Chapters Close

Preface 1. Part 1: Blockchain and Ethereum Basics
2. Chapter 1: Blockchain and Cryptocurrency FREE CHAPTER 3. Chapter 2: Ethereum Architecture and Ecosystem 4. Chapter 3: Decentralized Finance 5. Chapter 4: EVM-Compatible Blockchain Networks 6. Chapter 5: Deep Research and the Latest Developments in Ethereum 7. Part 2:Ethereum Development Fundamentals
8. Chapter 6: Fundamentals of Solidity 9. Chapter 7: Web3 API Fundamentals 10. Chapter 8: Developing Your Own Cryptocurrency 11. Part 3: Ethereum Development Fundamentals
12. Chapter 9: Smart Contract Development and Test Fundamentals 13. Chapter 10: Writing a Frontend to Build the NFT Marketplace DApp 14. Chapter 11: Ethereum Tools and Frameworks 15. Part 4:Production and Deployment
16. Chapter 12: Setting Up Ethereum Private Chain 17. Chapter 13: Deployment of Your DApps 18. Chapter 14: Building Ethereum Wallets 19. Chapter 15: Oracles, Technology, and Layer 2 in Practice 20. Part 5:Conclusion
21. Chapter 16: Conclusion 22. Index 23. Other Books You May Enjoy

Cross-chain in practice

Now that we’ve had a high-level overview of the Avalanche blockchain and its bridge design, let’s learn how to move an asset (Tether – USDT) from the Ethereum network to the Avalanche blockchain via Avalanche Bridge.

Bridge tokens from Ethereum to Avalanche

In this section, we will bridge a USDT token from the Ethereum mainnet to the Avalanche network C-Chain. To move a token or DApp from the Ethereum mainnet to Avalanche, we need to set up a few prerequisites.

Adding Avalanche to MetaMask

Similar to other examples covered in this book, open MetaMask and click your network’s name. Then, click the Add Network button at the bottom of the MetaMask pop-up window and enter and save the following network details:

The MetaMask wallet will display a confirmation prompt for adding Avalanche Network C-Chain. Refer to the following screenshot for a visual representation of the prompt:

Figure 15.12 – Connecting Avalanche Network C-Chain from MetaMask

Figure 15.12 – Connecting Avalanche Network C-Chain from MetaMask

Now, you will be connected to Avalanche Network.

Getting USDT tokens

You can find an exchange, such as Coinbase, Binance, Kraken, crypto.com, and others, for buying, selling, and trading USDT, and send it to your MetaMask account. In this section, we will demonstrate how to bridge the USDT token from Ethereum to Avalanche:

  1. Open the Ava Labs Core website. Avalanche’s website provides core Web3 functions that can integrate Avalanche apps, subnets, bridges, and NFTs for users.
  2. The Ava Labs Core website serves as a centralized platform that provides users with access to a wide range of Web3 functionalities. The following screenshot shows the Ava Labs Core website. Within the Command Center section of the website, users can easily send, receive, bridge, swap, and buy assets. Additionally, there is an option to connect your wallet to the bridge for seamless integration. In the next step, we will explore how to connect the Avalanche chain to our MetaMask wallet, enabling us to interact with the Avalanche network directly from our wallet interface:
Figure 15.13 – Avalanche core website

Figure 15.13 – Avalanche core website

  1. Connect the MetaMask wallet:
Figure 15.14 – Connecting to Avalanche from MetaMask

Figure 15.14 – Connecting to Avalanche from MetaMask

  1. Import a USDT token into MetaMask.

The Tether USDT Ethereum address is as follows:

0xdac17f958d2ee523a2206206994597c13d831ec7.
  1. Import the Tether USDT token into MetaMask by clicking Assets, then Import Tokens:
Figure 15.15 – Adding a Tether USDT token to MetaMask’s Ethereum network

Figure 15.15 – Adding a Tether USDT token to MetaMask’s Ethereum network

Now that the token has been set up in the wallet, we can bridge the token from Ethereum to Avalanche. This process will allow us to transfer the token seamlessly between the two networks, enabling us to leverage the benefits of both ecosystems.

Bridging a token from Ethereum to Avalanche

Let’s learn how to bridge the token from Ethereum to Avalanche and explore the interoperability of these networks:

  1. To move the USDT tokens to Avalanche Network C-Chain, use the Bridge option in the Command Center section. Make sure MetaMask is connected to the Ethereum network.
  2. The From network will be Ethereum, while the To network will be Avalanche. Select USDT Token and enter $10. Then, click the Bridge Tokens button:
Figure 15.16 – Bridging a token from USDT to Avalanche

Figure 15.16 – Bridging a token from USDT to Avalanche

  1. After clicking the Bridge Tokens button, MetaMask will ask you to confirm this transaction. Once you’ve done this, the bridge transaction will start. Notice that the gas fee is $2.50:
Figure 15.17 – Confirming the bridge token transfer

Figure 15.17 – Confirming the bridge token transfer

  1. Wait for the bridge transaction to be completed. This will take some time (depending on the two network speeds):
Figure 15.18 – Waiting for the bridge transaction to be completed

Figure 15.18 – Waiting for the bridge transaction to be completed

  1. Now, you must import USDT into Avalanche. To view USDT in Avalanche, you need to import Avalanche’s USDT token address into the wallet. Here is theTether (Avalanche) smart contract address: 0xc7198437980c041c805a1edcba50c1ce5db95118.

The following screenshot demonstrates the process of importing the USDT token into the MetaMask wallet for the Avalanche network. This step is essential to ensure that we can view and interact with the USDT token directly within the Avalanche network. By importing the token, we can seamlessly manage and utilize USDT in Avalanche-based decentralized applications and transactions. Let’s take a close look at the following screenshot to understand this process:

Figure 15.19 – Importing the USDT token into MetaMask’s Avalanche network

Figure 15.19 – Importing the USDT token into MetaMask’s Avalanche network

You should see that around 7 USDT was transferred to the Avalanche network:

Figure 15.20 – 7 USDT was transferred from Ethereum to the Avalanche network

Figure 15.20 – 7 USDT was transferred from Ethereum to the Avalanche network

With that, we have bridged tokens from Ethereum to Avalanche. In this section, we successfully transferred the USDT tokens from the Ethereum network to the Avalanche network. In the next section, we will shift our focus to bridging ETH from Ethereum to Polygon (MATIC). Stay tuned as we explore the process of bridging assets between these two blockchain networks.

Bridging ETH from Ethereum to Polygon (MATIC)

In the previous section, we discussed Polygon Bridge, which allows users to bridge tokens in two ways by offering two types of bridges (Plasma and PoS). The PoS bridge is the recommended option for most users as it allows Ether (ETH) and most ERC tokens, including ERC-20, ERC-721, and ERC-1155, to be transferred. In this section, we will show you how to use Polygon Bridge to transfer ETH funds between the Goerli and Mumbai testnets.

Before you start, ensure you have some test Ether tokens in your Ethereum wallet:

  1. Visit Polygon Web Wallet (https://wallet.polygon.technology/) and log in by clicking Polygon Bridge:
Figure 15.21 – The Polygon Web Wallet page

Figure 15.21 – The Polygon Web Wallet page

  1. Select MetaMask and connect Polygon Bridge to the MetaMask wallet.
  2. The page will redirect you to the Polygon Bridge page, where you can transfer ether assets from Goerli Chain to Polygon Mumbai Chain.
  3. We will transfer 0.01 ETH to Mumbai Chain. Enter 0.01 next to ETH:
Figure 15.22 – The Polygon Bridge page

Figure 15.22 – The Polygon Bridge page

  1. Click on the Transfer button.
  2. You will see a MetaMask confirmation popup. Confirm the transaction; your asset should be deposited within 7-8 minutes:
Figure 15.23 – Confirming that assets will be transferred from Goerli Chain to Polygon Mumbai Chain

Figure 15.23 – Confirming that assets will be transferred from Goerli Chain to Polygon Mumbai Chain

  1. After this, an important page will appear, showing you what is and isn’t supported. Click Continue.
  2. The transfer will start. The Transfer In Progress page will display three steps – Approve, Confirmed, and Completed:
Figure 15.24 – Polygon Bridge transfer token process

Figure 15.24 – Polygon Bridge transfer token process

  1. After waiting 7-8 minutes, the transfer will be completed:
Figure 15.25 – Complete transfer from Goerli Chain to Polygon Mumbai Chain

Figure 15.25 – Complete transfer from Goerli Chain to Polygon Mumbai Chain

  1. Now, if we go to Polygon’s Assets dashboard, we will see the transferred ETH values:
Figure 15.26 – The Polygon Wallet dashboard

Figure 15.26 – The Polygon Wallet dashboard

  1. If you want to see the Polygon Ether token in MetaMask, add Polygon Mumbai testnets by entering the following network information:

The following screenshot showcases the network value of Polygon (MATIC) within the MetaMask wallet interface:

Figure 15.27 – Adding a Polygon network in MetaMask

Figure 15.27 – Adding a Polygon network in MetaMask

  1. Once you’ve connected to Polygon testnets in MetaMask, you can add the Polygon ETH to your MetaMask wallet by clicking ETH, then Add to Wallet:
Figure 15.28 – Adding an ETH token to a wallet

Figure 15.28 – Adding an ETH token to a wallet

  1. Now, you will be able to view the transferred ETH in your Polygon MetaMask wallet, as shown in the following screenshot:
Figure 15.29 – Transferred token in Polygon wallet

Figure 15.29 – Transferred token in Polygon wallet

In this section, we explored the inner workings of cross-chain bridges, investigated their vulnerabilities, and examined popular bridge implementations. Additionally, we engaged in hands-on cross-chain examples, successfully transferring tokens between the Avalanche and Ethereum networks, as well as between different Polygon and Ethereum networks. Now, we will dive into the exciting realm of Layer 2 solutions, a highly relevant and captivating topic in the blockchain space. Layer 2 solutions offer enhanced scalability and advanced functionalities to blockchain networks. Let’s discover the world of Layer 2 technologies and their practical applications.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image