There is a story from our CTO Valery Dubrava (part I)
The purpose of our service LastWill is automatic (without involving third parties) execution of the wills (make coins transfer in case of various events). One of the main problems during the service implementation — understand the moment when event is happened.
Let’s consider the event — no activity with user’s wallet (no incomes/outcomes) in other words no movements of coins at a certain address (addresses) in the ethereum network.
Due to the fact that the information in the network is completely open, you can see the history of all transactions of any account (address). At the moment, from smart contract, such information is not available. But there are various services (for example, etherscan.io), whose API allows you to select the transaction history at a specific address.
The next limitation is that the contract can not initiate any interactions with the “outside world”, and the outside world can interact only through network transactions. In simple words, there is no way to make an HTTP request to a node. And the oraclize.it service comes to our aid!
Service Oraclize allows you to initiate interaction with the “outside world”. In addition to HTTP, there are other ways of interaction, which allows you to do Oraclize, for example, the generation of random numbers. More information can be found in the documentation. We are only interested in HTTP.
There are no exceptions to the implementation of Oraclize’s external interaction. A contract in an ethereum network can not call an external service. But it can create an event that will be visible to external services. In more detail, the logic of the service can be seen in the diagram below:
The scheme shows that our contract (LastWill) prepares the URL for the request and passes it to a special API contract (the LastWill contract inherits it).
The API contract gets the current Oraclize Contract address (using the Address Provider contract), and passes the URL to it. Step 2 is an external call. The address is received only on the first call, then the interaction goes directly. The first call is free of charge =)
Oraclize Contract publishes an event with our URL, so that the oraclize web service can get it (after adding the transaction to the block). The Web service executes the request, processes it, and prepares the response.
The Web service creates a new transaction that passes the result of the request to the callback method of the API contract that implements the LastWill contract.
It is important to understand that the request is not synchronous, that is, in the transaction in which it was initiated there will be no response.