Oracles With Serverless

What are Oracles on Web3?

Oracles in Web3 are third-party services or systems that connect blockchains and smart contracts to external, off-chain data sources, APIs, or real-world events. Smart contracts are self-executing programs that run on blockchains, but they can only access on-chain data. Many practical decentralized applications (dApps)—such as those in decentralized finance (DeFi), insurance, supply chain, and gaming—require real-world data like asset prices, weather conditions, or event outcomes to function. Oracles provide this critical link, allowing smart contracts to execute based on external information.

How Serverless enables Oracles?

Serverless functions run within Trusted Execution Environments (TEEs), ensuring that computations are secure, tamper-proof, and trustless. These functions can fetch off-chain data from reputable sources while verifying the authenticity of the data. They can also be seamlessly integrated with smart contracts on the blockchain, enabling trustless, on-demand or periodic callback triggers. This allows smart contracts to reliably access and react to external data through the Oyster Serverless platform.

Example Application

Let’s consider a DeFi application where users can place cut-off orders to exchange cryptocurrencies based on specific price conditions. To enable this, a serverless oracle can be set up to periodically fetch exchange rates—say, every 30 seconds—from a reputed off-chain source. The serverless function, running in a secure enclave, monitors the price feed and triggers a callback to the smart contract with exchange price, which then executes the trade on-chain, if exchange price met the cut-off requirement. This setup allows the smart contract to interact with real-time market data without relying on a centralized backend, ensuring that orders are executed fairly and trustlessly.

Benefits

Using serverless oracles offers several key advantages. They provide high-speed data availability, ensuring that smart contracts receive timely and accurate off-chain information. By running within Trusted Execution Environments (TEEs), these functions offer strong guarantees against tampering and attacks, maintaining the integrity of the data and computation. Additionally, serverless platforms are backed by high-availability providers, minimizing downtime and ensuring reliable performance. This model is also cost-effective, as resources are only used when needed, eliminating the overhead of maintaining dedicated infrastructure. Finally, serverless oracles are easy to integrate with existing smart contracts, making them a developer-friendly solution for enhancing dApps with real-world data.