Reader small image

You're reading from  Learn Ethereum - Second Edition

Product typeBook
Published inAug 2023
PublisherPackt
ISBN-139781804616512
Edition2nd Edition
Concepts
Right arrow
Authors (3):
Xun (Brian) Wu
Xun (Brian) Wu
author image
Xun (Brian) Wu

Xun (Brian) Wu is a senior blockchain architect and consultant. With over 20 years of hands-on experience across various technologies, including Blockchain, big data, cloud, AI, systems, and infrastructure, Brian has worked on more than 50 projects in his career. He has authored nine books, which have been published by O'Reilly, Packt, and Apress, focusing on popular fields within the Blockchain industry. The titles of his books include: Learn Ethereum (First Edition), Learn Ethereum (Second Edition), Blockchain for Teens, Hands-On Smart Contract Development with Hyperledger Fabric V2, Hyperledger Cookbook, Blockchain Quick Start Guide, Security Tokens and Stablecoins Quick Start Guide, Blockchain by Example, and Seven NoSQL Databases in a Week.
Read more about Xun (Brian) Wu

Zhihong Zou
Zhihong Zou
author image
Zhihong Zou

Zhihong Zou is an innovative technology leader with over 20 years of experience delivering cutting-edge enterprise solutions. He has led transformative solutions in telecommunications, healthcare, and government that leverage blockchain, AI/ML, and modern cloud architectures to solve complex business challenges. As an insightful visionary and trusted advisor, Zhihong is passionate about driving digital transformation and future-proofing organizations. He holds an M.Sc degree in computational mathematics and an M.Sc in computer science. Zhihong has authored multiple papers on numerical computing and two popular editions of the book Learn Ethereum. In his free time, Zhihong enjoys sharing his blockchain expertise as an advocate and writer.
Read more about Zhihong Zou

Dongying Song
Dongying Song
author image
Dongying Song

Dongying Song has been a noteworthy leader in Blockchain, Ethereum, big data, ML, data science, and the cloud application development space for over 8 years. As an experienced software engineer and data scientist, she has worked for top-tier banks and pharmaceutical and technology companies. Dongying holds a master's degree in statistics from Columbia University and majored in mathematics during her undergraduate years. Her recent activities focus on Blockchain, Ethereum, and smart contract developments.
Read more about Dongying Song

View More author details
Right arrow

Oracles, Technology, and Layer 2 in Practice

In this chapter, we will introduce the concept of oracles and understand how oracles work in the decentralized Web 3.0 ecosystem, react to real-world events, and interoperate with traditional systems. We will build an oracle example to get a real-time randomness number from a blockchain. Then, we’ll briefly review the Ethereum cross-chain bridge technology and learn how it allows users to send tokens and arbitrary data between blockchain networks. Lastly, we will explore Layer 2 technologies in practice.

The topics that we will cover in this chapter are as follows:

  • Understanding oracles
  • Working with oracles
  • Diving deep into cross-chain technology
  • Cross-chain in practice
  • Working with Layer 2

Technical requirements

For all the source code for this book, please refer to the following GitHub link: https://github.com/PacktPublishing/Learn-Ethereum-Second-Edition/.

Understanding oracles

In Chapter 3, Decentralized Finance, and Chapter 4, EVM-Compatible Blockchain Networks, we briefly discussed blockchain oracles. They are middleware that connects on-chain smart contracts with off-chain real-world data by providing external information. A blockchain oracle triggers smart contract execution when certain predefined rules and conditions in the contract are met.

Oracles enable smart contracts to interact with real-world data and systems that exist outside the blockchain network. They serve as trusted sources of information, bringing in data such as market prices, weather conditions, stock prices, sports scores, and more.

In the upcoming section, we will explore various examples of blockchain oracles and how they enhance the functionality and capabilities of smart contracts. These examples will highlight the practical applications and the value that oracles bring to blockchain-based systems. Let’s delve into the exciting world of blockchain...

Working with oracles

Oracles play a vital role in bridging the gap between the blockchain network and the real world, enabling real-world data and services to be integrated into decentralized applications. In the decentralized world, several top oracle providers are widely used and trusted for their reliability and accuracy in delivering external information to blockchain systems. Here are the top 10 Oracle providers by Market Cap (from coingecko):

Figure 15.3 – Top 10 Oracle providers by Market Cap (from coingecko)

Figure 15.3 – Top 10 Oracle providers by Market Cap (from coingecko)

Now that we have an overview of the top 10 current oracle providers from the preceding diagram, let’s explore each of these providers in detail:

  • Chainlink: The Chainlink network, which uses the LINK cryptocurrency, was launched in June 2017 and is the leading oracle provider in the market. It is a decentralized blockchain oracle network built on Ethereum. The network provides secure and tamper-proof data from off-chain...

Diving deep into cross-chain technology

In Chapter 4, EVM-Compatible Blockchain Networks, we discussed common cross-chain bridge designs, including natively verified bridge designs, locally verified bridge designs, and externally verified bridge designs. The following sub-sections will quickly go over the main concepts and how to build a cross-chain bridge in practice.

How does a cross-chain bridge work?

One of the simplest and most common types of bridge is a cross-chain bridge. It uses a mechanism known as the lock-and-mint model to move value cross-chain. In this section, we’ll learn how the lock-and-mint model works in practice.

To understand how lock-and-mint model bridges work, let’s consider a user, Alice, who wants to move USDT assets from Ethereum to the Polygon blockchain:

  1. First, Alice deposits amounts of the Ethereum USDT in a specific contract address owned by the bridge on the source chain Ethereum and pays the transaction fee. A trusted...

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:

...

Working with Layer 2

With the number of users growing on the Ethereum network, the network’s high gas fees and congestion are becoming a primary problem for DApps. Therefore, as the demand for Ethereum increases, the scaling problem has become a top priority. There are various types of Ethereum scaling solutions that help relieve pressure by expanding the Ethereum network’s capacity. There are two types of Ethereum scaling solutions, including Layer 1 and Layer 2. Layer-2 scaling has become a hot topic in the crypto industry recently.

We discussed many Layer-2 scaling solutions, such as state channels, sidechains, and rollups, including optimistic and zero-knowledge (ZK) rollups, in Chapter 2, Ethereum Architecture and Ecosystem and Chapter 4, EVM-Compatible Blockchain Networks .

The following diagram provides an overview of the various Layer-2 scaling solutions:

Figure 15.30 – Layer-2 scaling solutions

Figure 15.30 – Layer-2 scaling solutions

In the next section, we...

Summary

In this chapter, you learned about oracles in terms of their features and types. We discussed how an oracle can act as a bridge between the blockchain network and the real world by explaining various blockchain oracle examples. We studied the most popular oracle service, known as Chainlink, and used the Chainlink API to write a VRF dice-rolling game.

With our knowledge of cross-chain technology from previous chapters, in the Diving deep into cross-chain technology section, we covered how cross-chain bridges work and covered their vulnerabilities. As we saw, many types of cross-chain are available in the industry. We then ran a real-world example of bridging tokens from Ethereum to Avalanche. We also demonstrated how to move ETH from Ethereum to Polygon (MATIC).

After reviewing various Layer 2 solutions, including optimistic rollups and ZK rollups, we learned about the differences between these rollup solutions. We also discussed zk-SNARKs and zk-STARKs. Finally, we wrote...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learn Ethereum - Second Edition
Published in: Aug 2023Publisher: PacktISBN-13: 9781804616512
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.
undefined
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 $15.99/month. Cancel anytime

Authors (3)

author image
Xun (Brian) Wu

Xun (Brian) Wu is a senior blockchain architect and consultant. With over 20 years of hands-on experience across various technologies, including Blockchain, big data, cloud, AI, systems, and infrastructure, Brian has worked on more than 50 projects in his career. He has authored nine books, which have been published by O'Reilly, Packt, and Apress, focusing on popular fields within the Blockchain industry. The titles of his books include: Learn Ethereum (First Edition), Learn Ethereum (Second Edition), Blockchain for Teens, Hands-On Smart Contract Development with Hyperledger Fabric V2, Hyperledger Cookbook, Blockchain Quick Start Guide, Security Tokens and Stablecoins Quick Start Guide, Blockchain by Example, and Seven NoSQL Databases in a Week.
Read more about Xun (Brian) Wu

author image
Zhihong Zou

Zhihong Zou is an innovative technology leader with over 20 years of experience delivering cutting-edge enterprise solutions. He has led transformative solutions in telecommunications, healthcare, and government that leverage blockchain, AI/ML, and modern cloud architectures to solve complex business challenges. As an insightful visionary and trusted advisor, Zhihong is passionate about driving digital transformation and future-proofing organizations. He holds an M.Sc degree in computational mathematics and an M.Sc in computer science. Zhihong has authored multiple papers on numerical computing and two popular editions of the book Learn Ethereum. In his free time, Zhihong enjoys sharing his blockchain expertise as an advocate and writer.
Read more about Zhihong Zou

author image
Dongying Song

Dongying Song has been a noteworthy leader in Blockchain, Ethereum, big data, ML, data science, and the cloud application development space for over 8 years. As an experienced software engineer and data scientist, she has worked for top-tier banks and pharmaceutical and technology companies. Dongying holds a master's degree in statistics from Columbia University and majored in mathematics during her undergraduate years. Her recent activities focus on Blockchain, Ethereum, and smart contract developments.
Read more about Dongying Song