current position:Home>How smart contracts call data from outside the chain

How smart contracts call data from outside the chain

2022-02-03 23:37:47 Q & A of Denglian community

We're writing solidity When you code, you often need to pass in parameters , But if a parameter needs to be from a trusted source outside the chain ( Even if it's centralized ) Read out , The caller of the contract is not allowed to enter , How should it be realized ?

A common scenario is the oracle , In fact, it also includes information obtained from any traditional source . Let's take the simplest example , My contract defines a uint a, A method function changeA() The function of , Is to put a Change to the temperature in Beijing today announced by the Central Meteorological Observatory ( This data is open source and easy to see ), How to achieve it ?

Take the answer 1:

One way is to have only trusted addresses , To submit information .

One way is to introduce an economic model to solve , For example, when submitting information , Need to pledge some money , To ensure the correctness of the data , If challenged , Will be fined .

Other answers 1:

copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.

Random recommended