0
0
Blockchain / Solidityprogramming~10 mins

Oracle integration (Chainlink) in Blockchain / Solidity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Oracle integration (Chainlink)
Smart Contract requests data
Chainlink Oracle receives request
Oracle fetches external data
Oracle sends data back to contract
Smart Contract receives and uses data
End
The smart contract asks Chainlink Oracle for data, Oracle fetches it from outside blockchain, then returns it to the contract for use.
Execution Sample
Blockchain / Solidity
contract Weather {
  int temperature;
  function requestTemperature() public {
    chainlinkRequest(...);
  }
  function fulfill(bytes32 id, int temp) public {
    temperature = temp;
  }
}
This contract requests temperature data via Chainlink and updates its state when Oracle responds.
Execution Table
StepActionSmart Contract StateOracle StateOutput/Result
1Smart contract calls requestTemperature()Request sentWaiting for requestRequest emitted
2Chainlink Oracle receives requestRequest sentRequest receivedOracle starts fetching data
3Oracle fetches external temperatureRequest sentFetching dataData retrieved from API
4Oracle sends data back to contractRequest sentData sentResponse transaction sent
5Contract fulfill() called with temptemperature updatedData sentTemperature stored
6Contract uses temperature datatemperature availableIdleContract logic proceeds
7EndFinal stateIdleProcess complete
💡 Process ends after contract receives and stores Oracle data
Variable Tracker
VariableStartAfter Step 1After Step 5Final
temperatureundefinedundefined25 (example)25
Key Moments - 3 Insights
Why does the contract wait after sending the request?
Because the Oracle fetches data asynchronously outside the blockchain, the contract must wait for the Oracle to call fulfill() later (see steps 2-5 in execution_table).
How does the contract know the data is from the Oracle?
The fulfill() function is called only by the Oracle's authorized address, ensuring data authenticity (step 5 in execution_table).
What happens if the Oracle never responds?
The contract will not update the variable and may remain waiting indefinitely or until timeout logic triggers (not shown in this simple trace).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the contract update its temperature variable?
AStep 5
BStep 3
CStep 2
DStep 6
💡 Hint
Check the 'Smart Contract State' column for when 'temperature updated' occurs.
According to variable_tracker, what is the temperature value after step 5?
Aundefined
B0
C25 (example)
Dnull
💡 Hint
Look at the 'After Step 5' column for the 'temperature' variable.
If the Oracle never sends data back, which step would never happen?
AStep 2
BStep 5
CStep 4
DStep 1
💡 Hint
Refer to execution_table rows where contract state changes after Oracle response.
Concept Snapshot
Oracle integration with Chainlink:
- Contract sends request to Oracle
- Oracle fetches external data asynchronously
- Oracle calls contract's fulfill() with data
- Contract updates state with received data
- Ensures real-world data on blockchain securely
Full Transcript
This visual trace shows how a smart contract uses Chainlink Oracle to get external data. First, the contract sends a request (step 1). The Oracle receives it and fetches data from outside blockchain (steps 2-3). Then Oracle sends the data back by calling fulfill() on the contract (step 5). The contract updates its variable with the new data and continues its logic (steps 6-7). Variables like temperature start undefined and update only after Oracle response. Key points include waiting for asynchronous Oracle response and verifying data authenticity. If Oracle never responds, contract state stays unchanged. This process securely connects blockchain contracts to real-world information.