How blockchain oracles work
Blockchain oracles are specialized services that act as bridges between the real world and blockchain technology. They provide smart contracts with relevant and necessary information from the outside world, such as exchange rates, payment statuses or even weather conditions. This data helps to automate and fulfill the terms of contracts without direct human intervention. The basic principle behind oracles is their ability to function outside of the blockchain by connecting to various online sources to collect data. Although oracles are not part of the blockchain itself, they play a key role in making it functional by acting as a trusted intermediary that reliably feeds external data into the system. Most oracles tend to be decentralized, avoiding the risks associated with dependence on a single source of data. This provides greater security and reliability to the system as data is verified and validated through a network of nodes before it is used in smart contracts. This approach minimizes the risk of manipulation and errors, ensuring that the information provided is accurate and up-to-date.Varieties of blockchain oracles
Blockchain oracles are categorized according to various aspects: mechanism of operation, data sources, data direction, and governance structure. Let’s take a look at the most common types of oracles.Push and pull oracles
Push and pull oracles differ in how they deliver data to on-chain smart contract. For push oracle, data provider constantly updates info, pushing newest data to centralized trusted contract. Read more about oracle model differences: ChainLink - Pull vs Push oracles. For pull oracle, users should retrieve latest data from off-chain data provider themselves, then verify it using oracle contract. Learn more about data verification flow with pull model oracles. Given TON actor-model, pull oracles prove to be more suited for real world applications.Centralized and decentralized oracles
Centralized oracles are controlled by a single party, which creates security and reliability risks. Decentralized oracles use multiple nodes to verify data, making them more secure and reliable.Cross-chain oracles
These oracles are used to transfer data between different blockchains and are a critical component of bridges. They are used for decentralized applications that use cross-chain transactions, such as cross-chain transfer of crypto assets from one network to another.Application of blockchain oracles
Blockchain oracles build bridges between the digital world of blockchains and real life, opening up a wide range of applications. Let’s take a look at some of the most popular uses of oracles.DeFi (decentralized finance)
Oracles play a critical role in the DeFi ecosystem by providing market price and cryptocurrency data. Price oracles allow DeFi platforms to link token values to real assets, which is essential for controlling liquidity and securing users’ positions. Additionally, oracles are vital for lending platforms, where accurate price data ensures proper collateral valuation and risk management, safeguarding both lenders and borrowers. This makes transactions more transparent and secure, contributing to the stability and reliability of financial transactions.Prediction markets
Oracles can automatically read and analyze data from a variety of sources to determine the occurrence of real life events. This allows prediction and insurance contracts to pay claims automatically, reducing the need to manually process each case and speeding up response times to events.Random number generation
It is difficult to generate random numbers in smart contracts because all operations must be reproducible and predictable, which contradicts the concept of randomness. Computational oracles solve this problem by bringing data from the outside world into contracts. They can generate verifiable random numbers for games and lotteries, ensuring fairness and transparency of results. Read more: Randomness in TONOracles in TON
Since TON execution model is asynchronous, the classic ways to interact with oracles (get methods during transaction) can’t be applied here, you can learn about differences in “Coming from Ethereum” article. The pattern to get data from oracle that works the best is Request-Response pattern - you send internal message to oracle contract and verify the response, getting needed data. This model works well with pull oracles, since you can always guarantee the lowest possible latency for real-world data. If you use push oracle, you will still need to process two internal messages (request and response) to retrieve data. However, data relevance is limited by data provider up-time and pushing intervals: if data provider pushes updated data every 10 minutes, you will commonly receive information that is outdated by 5 minutes. But using pull oracle, you can ensure pushes as often as your service needs, by updating the data yourself.Push oracle flow
- Data provider pushes latest data on-chain
- User contract, that needs prices on-chain, sends request message to trusted oracle contract
- Oracle contract replies to sender address with response internal message, containing requested data
- User contract receives oracle response, verifies sender address and then is ready to use provided data
Pull oracle flow
- Users off-chain backend calls API method on data provider
- Provider responses with signed price data (including timestamp till this data is valid)
- User contract sends “Verify that this price is correctly signed and valid” internal message to oracle contract
- Oracle contract verifies signature, timestamp and price feed id, if everything is okay sends response with prices back
- User contract receives response from oracle contract, checks if sender is really oracle, then can use provided data
