🎉 Gate.io Growth Points Lucky Draw Round 🔟 is Officially Live!
Draw Now 👉 https://www.gate.io/activities/creditprize?now_period=10
🌟 How to Earn Growth Points for the Draw?
1️⃣ Enter 'Post', and tap the points icon next to your avatar to enter 'Community Center'.
2️⃣ Complete tasks like post, comment, and like to earn Growth Points.
🎁 Every 300 Growth Points to draw 1 chance, win MacBook Air, Gate x Inter Milan Football, Futures Voucher, Points, and more amazing prizes!
⏰ Ends on May 4, 16:00 PM (UTC)
Details: https://www.gate.io/announcements/article/44619
#GrowthPoints#
Chainlink Engineers: How Oracles Connect Web2 and Web3
Speaking: Frank, Developer Relations Engineer, Chainlink Labs
Organization: aididiaojp.eth, Foresight News
I'm Frank, a Developer Relations Engineer at Chainlink Labs. My main job is to enable more developers, or builders who are passionate about this industry, to learn more about oracle machines. Based on the smart contracts under our current infrastructure, we can think of it as a hybrid smart contract. Smart contracts can be better closely integrated with various data in the Web2 world, including computing services, and then based on this architecture, the things that smart contracts on the chain can do are greatly expanded.
In today's sharing, I will first introduce the concept of oracle machine, and then based on the concept of oracle machine, I will briefly introduce the decentralized oracle machine network and some services we can provide, including data services and computing services.
What is an oracle?
From Web 1 to Web 2 to Web 3, the state of the network and data is constantly changing. At the beginning, Web1 was a website service whose data could only be read statically. When it developed to the Web2 stage, the data became readable, writable, and participateable. Many large companies have created business empires based on their own services. They will store all user data in their own databases. If necessary, they can actually own and modify user data. In this case, a question arises, that is, some data we create on the Internet or in the virtual world sometimes has some value, so who does this value belong to? Based on this background, we hope to be able to solve this problem well in the Web 3 stage. All the data in the Web 3 stage does not exist in a server or in a node. It has a decentralized network, and the decentralized network is a multi-book system composed of multiple nodes. Data is stored in multiple nodes, and only when each node agrees with the modification and storage of data, can the final data be saved. Then this will bring us a benefit, that is, no matter what modification we want to make to the data, we need to modify it according to the pre-agreed consensus. For example, if I want to modify the wallet balance, if no one sends me money, no matter how the owner of the data wants to modify it, he will eventually fail the consensus process, which makes the wallet balance unable to be modified. Only when the owner of the data sends a transaction that conforms to the rules can the data be finally modified, which brings a very obvious benefit. At the same time, it also brings some disadvantages. The biggest disadvantage is that it makes the system a deterministic system. That is to say, because there will be a consensus process throughout the process, it can only perform operations that others can verify. When you send an operation, others need to execute your operation, and if other nodes execute the operation successfully, they can actually return the result. As for whether it is more than 50% or 70%, it depends on the consensus algorithm. In the end, the operation can be written into the transaction, and the transaction can be written into the block to become a complete transaction.
But if we need to do some non-deterministic operations, such as obtaining some API data and generating random numbers outside the blockchain, the deterministic blockchain system cannot be completed. Our lottery draw needs to generate random numbers, or the on-chain protocol needs to know the asset price off the chain, such as acquiring the price of stocks or commodities, which is a non-deterministic operation and cannot be completed by the blockchain itself. Another example is API calls. If I, as a node in the network, call external API data, and then I tell other nodes in the network the result, other nodes will also execute it in order to verify the authenticity of the result. Do the same operation and get a result. But for an external API, if different people fetch the same API at different times, the server may hang up, or the service may be suspended, or the data may change over time. You do the same thing at different times, and the results you get are inconsistent. As long as the result is inconsistent, the final operation cannot be entered into a block, and there is no way to complete it. This is after we have data ownership, we also need to bear some of the shortcomings it brings.
To solve this problem, we need to rely on oracles. The blockchain is an isolated and deterministic system. It cannot actively obtain data from off-chain. The emergence of the oracle machine is to solve this problem. Two or three years ago, the concept of the oracle machine appeared, but there were not many applicable scenarios at that time, and it had great limitations. For example, when you want to obtain some market data, upload stock data to the blockchain network, or make a structure to put logic on the chain for execution, but put the asset side on the chain, and protect the normal progress of transactions through smart contracts, etc., At this time, some data needs to be obtained from the chain, and data synchronization needs to be performed periodically, including bank payment or retail data, and even some other public event data, such as weather conditions, geographic information, logistics information, sports information, etc. Game results, etc. These data cannot be obtained without the oracle machine. This will make the ecology on the chain very limited. With the continuous development of the Web 3 ecosystem, the links between the two worlds of Web 3 and Web 2 will become closer and closer. If we want Web3 to be adopted on a large scale, or to be used by more people, it must provide very rich functions, not just limited to some operations that can only be done through the original data on the chain.
The oracle machine probably became popular in 2020, when it was DeFiSummer, and most people realized it. At the beginning, the oracle machine did very simple things. For example, if you want to obtain external data and upload it to the decentralized network, that is, the blockchain, the easiest way is to establish a centralized node under the chain, that is, to build A server, then obtains data through the server, and finally writes the data into the deduplicated blockchain network, then this model is called a centralized oracle. Although it is relatively simple to implement, it will bring some problems. For example, it has the risk of a single point of failure, that is, the centralized node may cause downtime due to its own basic reasons. Another possibility is that if the service provided by the smart contract on the chain depends on the data provided by the centralized node, and if the amount of funds involved in the smart contract on the chain is very large, then this centralized oracle machine may pass its own Data that can be manipulated to launch an attack on the service. As long as the benefits are large enough and there is no way to achieve completeness through technical means, then this is a single point of failure. We want to put the application in the decentralized network, including Ethereum or other Layer 2 ecosystems. In fact, we also hope that we can ensure the fairness of our application, that is, the smart contract, through hundreds or thousands of oracle nodes in the network. and security.
Of course, if we rely on centralized nodes to obtain data terminals, even if other aspects of security can be guaranteed, but the most important asset data terminal cannot guarantee security, it will make the entire dApp meaningless. So after the centralized oracle machine, there is a decentralized oracle machine network, which can well solve the risk of single point of failure we just mentioned. The biggest difference in the decentralized oracle network is not that a single oracle node provides services to the decentralized network, but through the decentralized oracle network. It can also be understood as a kind of Layer2, that is, every decentralized The nodes in the decentralized oracle network can obtain data through their own data sources, and after obtaining the results, they can perform data aggregation with other decentralized networks, which can also be understood as a consensus process, including checking whether the data Whether there are nodes, or whether the returned data deviates too far from the average value, or simply make an average value, then aggregate the data, etc., and then write it to the decentralized network. One of the benefits brought by this method is that technically it can guarantee that the service will not be interrupted unless all nodes in the decentralized oracle network stop serving, but this possibility is very low. In addition, on the data side, it can also be guaranteed that the data provided by the oracle to the contract on the chain is not controlled by a single node, but by many nodes. If you want to manipulate data to launch an attack, the cost will be very high, which is equivalent to attacking Layer 2, or even a decentralized network like Ethereum, which is basically unlikely to succeed.
The decentralized network can greatly improve the security and fairness of data received by smart contracts. For users, we are just a decentralized oracle network, but based on the decentralized oracle network, we can provide some other services, such as data services, computing services, and cross-chain services. If it is based on the oracle machine to provide data to the network, in fact, there are some more complex and costly operations that can also be completed off-chain, that is, it is packaged to the off-chain oracle network for calculation, and then written back to the security comparison high blockchain. If we can obtain data from off-chain, we can also obtain data from other chains and write it to this blockchain, which actually involves cross-chain. As long as the security of the decentralized oracle network is strong enough, it can guarantee the security of data services, computing services and cross-chain services based on it. Chainlink provides a variety of services based on decentralized oracles, which can connect Web 3 and Web 2 data, including Layer 1 and Layer 2 data, so that everyone can obtain as much corresponding data and services as possible.
What are the services provided by Chainlink oracles?
Next, let me briefly introduce the services provided by Chainlink oracles. Of course, there are many services based on Chainlink, and I will share some services with more applicable scenarios.
If you want to make some innovations in the fields of DeFi, GameFi, NFT, and SocialFi in the future, there is a high probability that you will need an oracle to obtain data. Because you must obtain chain data in a very decentralized and secure way, and write it back to your smart contract on the chain.
The first service is price feed, which may also be a term that you often hear before, and it will explode in DeFiSummer in 2020. In 2020, many DeFi projects appeared, starting with Uniswap, followed by the lending contract Compound, and then the synthetic asset project Synthetics and other applications. They all have a large demand for off-chain data, because only secure data can be used. Data can be used by users in a decentralized manner through contracts, and an important role is played by the price feed service of the oracle.
The figure above is the basic flowchart of the price feed service, which includes 3 important participants. The first is the decentralized network of oracle machines we just mentioned; the second is data providers, which may be exchanges or other large authoritative institutions, all of which can serve as data providers; the third is a user contract. The process shown in the above figure is very simple. Each data provider can provide a node of the Chanlink oracle network through the data source interface or service, and each node of the oracle network can also obtain data according to its own service. , and then through the aggregation process, the data obtained by each channel is written into the verification contract deployed on the chain. If it passes the verification, the data can be recorded and can be used by users in the future. This is the whole process. The client only needs to use the contract to obtain and use multiple data.
There are many use cases for price feeding, such as the Compound, Uniswap and Synthetics we mentioned just now, they need to map the assets in Web2 to Web3, and they need external mechanisms to provide asset prices. Just like a stablecoin, it is based on how many assets can issue as many stablecoins, and its asset price should also be obtained based on the oracle machine. In addition, like some asset management platforms and popular derivatives trading applications, they are highly dependent on prices, so these are actually important users of price feeding services. From a trend point of view, the demand for price feed services is rising exponentially. Data usage has been growing even in less active markets.
Next, I will introduce the second more distinctive service, Any API. Simply put, it helps smart contracts on the chain to obtain some non-standard data, such as some long-tail data. These data may only be available to certain people or certain contracts, but it is not standard data like token prices or asset prices. Many DApps require non-standard data. For example, Web 3 insurance business applications need to obtain weather data or flight delay data. For example, greenhouse gas can do some projects similar to ESG, including election sports games can be combined with prediction markets. We provide data markets based on Any API. In each data market, there are various data providers that provide external services based on their own data. As long as the user sends a request, he can write the data back to the user contract according to the service requirements. . Both the provider of data and the receiver of data are determined by the market. There is a market for users and data providers, and Chainlink does not officially monopolize all data and then provide data to the chain.
The workflow of Any API and price feed is actually quite consistent. The contract first sends a request, and then the request will be discovered by the Chanlink nodes. After discovery, Chanlink can select the required data according to the request, and then write it back to the blockchain. AnyAPI can provide users with a variety of data, but it has a characteristic that although it is built relatively quickly, it is provided by a single node. What AnyAPI wants to do is to obtain data as quickly as possible in a simple way, instead of obtaining data through the decentralized network oracle machine we mentioned before.
Later, as the diversity of data requirements increased, many non-standard data also hoped to be written back to the chain in a decentralized manner. We also created a new service called Functions in early April this year. Simply put, it executes any user request through the decentralized oracle network. Users can use some advanced programming language such as Java to write out the operation program, no longer can only be written in Solidity language, the program written in Java is definitely richer than Solidity. The Functions service can encapsulate the written program into a request and send it to the entire oracle network. Every node in the network will perform the same operation, which may be computing services, data acquisition services, or other services. After each node executes and gets the result, it goes through the aggregation process we just mentioned, and then writes it back into the smart contract.
Compared with the feed price, its degree of freedom is very high. That is to say, the smart contract can be given an external interface to use any method it wants. It can also write some of the logic it has to do into the contract, and then it is not executed by the blockchain, but by the oracle machine, which is equivalent to directly embedding the oracle machine service into the smart contract, becoming a hybrid type of smart contract. If you do it in this way, then your execution is guaranteed through the decentralized network, and your non-deterministic operations are operations that cannot be done on the blockchain, and can be performed through the decentralized oracle machine The network executes and returns the result. Overall, it can greatly improve the functionality of smart contracts. The functions it can do will be more abundant than before, and it is also very simple to apply on the client side. You only need to add two functions to your contract, and you can directly use the decentralized oracle network as part of your smart contract. to use. And it is also very friendly to traditional Web2 programmers, because the execution logic can be completed through traditional programming languages. The overall process has not changed. The request is sent, then sent to the decentralized oracle network, aggregated after execution, and finally written back to the user's smart contract.
The above is what I shared about the oracle machine and some services that the decentralized network based on the oracle machine can provide.