预言机问题
理解智能合约为何无法直接访问链下数据,以及这对 DApp 功能带来的挑战。
预言机问题 是 CoddyKit 上的免费 Web3 & DApp Development Fundamentals 课时。 这是第 1 节课,共 3 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Web3 & DApp Development Fundamentals 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Web3 & DApp Development Fundamentals 课程共包含 3 节课。
本课时的部分内容尚未翻译,以英文显示。
What is Off-Chain Data?
Welcome! In Web3, DApps often need information that isn't stored directly on the blockchain. This is called off-chain data.
Think of things like current stock prices, real-time weather reports, or the outcome of a sports game. This data exists in the 'real world' outside the blockchain's network.
Blockchains Live in a Bubble
Blockchains are designed to be isolated and self-contained environments. This is crucial for their security and reliability.
Every node in the network must agree on the exact state of the blockchain. If a smart contract could directly fetch external data, different nodes might get different results, breaking consensus.
Defining The Oracle Problem
The Oracle Problem refers to the challenge of securely and reliably bringing external, off-chain data onto a blockchain.
Smart contracts, by design, cannot directly 'see' or 'fetch' data from the internet. They operate in a deterministic, closed system.
Smart Contracts Can't Browse
Why can't a smart contract just make an API call like a regular web application?
- Determinism: All transactions must produce the same result across all nodes. An external API call might return different data at different times.
- Security: Directly calling external sources introduces vulnerabilities and potential attack vectors.
- Consensus: How would all nodes verify that the external data was indeed what the API returned?
DApp Limitations Without Oracles
Many powerful DApps need real-world data to function. Without a way to get this data, their utility is severely limited.
Imagine a decentralized finance (DeFi) lending platform that needs current asset prices, or an insurance DApp based on real-world events like weather or flight delays.
The Trust Dilemma
If a DApp relies on a single source to provide external data, that source becomes a centralized point of failure.
This undermines the core principle of decentralization. The data provider could be malicious, hacked, or simply go offline, jeopardizing the entire DApp.
Oracles: The Data Bridge
To solve the Oracle Problem, we introduce oracles. An oracle is a third-party service that finds and verifies real-world data, then sends it to a smart contract.
It acts as a secure bridge, allowing smart contracts to interact with the outside world without breaking their deterministic nature.
Ensuring Data Reliability
While oracles solve the 'access' problem, they introduce a new challenge: how do we trust the oracle itself?
The data provided by an oracle must be accurate, tamper-proof, and available. If the oracle provides bad data, the smart contract will execute based on that bad data.
Real-World Example Need
Consider a simple decentralized betting DApp:
- Users bet on the outcome of a football match.
- The smart contract needs to know the final score.
- It cannot directly access ESPN or other sports sites.
- An oracle is essential to feed the final score to the contract, enabling payouts.
Quick Check: Oracle Problem
Which of the following is the primary reason smart contracts cannot directly access real-world data like a traditional web application?
Recap: The Oracle Problem
You've learned about the critical Oracle Problem in Web3 development:
- Blockchains are isolated and deterministic.
- Smart contracts can't directly access off-chain data.
- Many DApps need real-world data to function.
- Oracles act as bridges, but introduce new trust challenges.
Next, we'll explore how decentralized oracle networks like Chainlink provide solutions to this problem!
常见问题解答
「预言机问题」课时是免费的吗?
是的 — 「预言机问题」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Web3 & DApp Development Fundamentals 课程的其余内容,请升级到 CoddyKit PRO。 Web3 & DApp Development Fundamentals 课程共包含 3 节课。
「预言机问题」这节课中我会学到什么?
理解智能合约为何无法直接访问链下数据,以及这对 DApp 功能带来的挑战。 你通过在浏览器中直接运行的动手代码来练习 Web3 & DApp Development Fundamentals,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Web3 & DApp Development Fundamentals 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Web3 & DApp Development Fundamentals 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 3 节。
「预言机问题」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Web3 & DApp Development Fundamentals 课中编写并运行代码吗?
能。每节 Web3 & DApp Development Fundamentals 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 预言机问题
- Chainlink 基础
- 获取链下数据