4

Suppose I have a contract which depends on the current price of a real-world asset (like the price of gold). How would the contract obtain that price? How would I ensure that every time the contract is run (say, by BPs), the same result is obtained?

1
  • Although eos mentions oracle, but it is difficult to find examples related to it.
    – smarteasy
    Jun 19, 2018 at 1:11

3 Answers 3

2

Contracts can't query off-chain data since that would make it impossible to reproduce the contracts' behavior. If you need to feed data into a contract, send it in an action. The contract can reject actions from unauthorized parties.

1

There needs to be an external service, usually called oracle that writes this data to blockchain.

Then contracts read this data off from the oracle contract.

Oracles can be third parties, compensated for writing this data. Or in the case of early ecosystem, you just run the oracle yourself on your server with a simple script that does

  • Fetching the data, usually from URL
  • Processing the result
  • Writing the interesting parts of data to EOS storage
  • Maintaining balance for the write operations

Because blockchain has to be deterministic, there is no way for smart contracts or block producers to rely on third party data sources.

0

This is decentralized application so generally you can't push/pull outside data to/from it. That's also the reason why Oracle service is there to responsible for it.

BTW, your question quite similar to this: How do you stream data from an input file when writing contracts on EOS?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.