0

I'm total newbie. Let's assume I want to create a contract that sell BTC when price reach 20.000$ for example, how can I do that? How smart contract check the price? How many times? I don't understand how smart contract can see the price of BTC and how many times check it.

Thank you

rod
  • 167
  • 3

1 Answers1

0

In theory

  • Imagine some service, which imports data from the "world outside" to blockchain. This is called Oracle and you can read about it here.
  • Now, we can find (or build our own!) Oracle which will constantly monitor Bitcoin price.
  • When the desired price is reached your smart contract will create an event, which will be recognised outside the blockchain and the further actions will be made.

In addition, you might want to read: Watching Solidity Events (more practice, less theory).

Roman Frolov
  • 3,177
  • 2
  • 11
  • 29
  • Thank you very much Roman. So instead of an Oracle can I call an API from an Exchange (for example) or I MUST get data from an Oracle? – rod Dec 21 '17 at 20:31
  • @rod what API are you referencing to? In blockchains we call such services Oracles. – Roman Frolov Dec 21 '17 at 20:34
  • Ok thank you. But where Oracle Is run? It run directly inside blockchain or where? Thank you very much – rod Dec 21 '17 at 20:44
  • @rod I think How do oracle services work under the hood is the best short answer to your question. – Roman Frolov Dec 21 '17 at 20:49
  • Thank you Roman. You are very helpful. In some way, I permit a specified Oracle to send data to my contract, and then the contract check this data. Is this correct? I don't understand HOW an oracle is linked with a contract... I see that smartcontract.com has a chainlink system. – rod Dec 21 '17 at 20:58
  • @rod don't worry, not many do. The interaction between Oraclize and an Ethereum smart contract is asynchronous. Any request for data is composed of two steps: 1) a transaction executing a function of a smart contract is sent by a user. The function contains a special instruction which manifest to Oraclize, who is constantly monitoring the Ethereum blockchain for such instruction, a request for data. 2) according to the parameters of such request, Oraclize will fetch or compute a result, build, sign and broadcast the transaction carrying the result. – Roman Frolov Dec 21 '17 at 21:08