Oracle Contracts on Ardor
See all lightweight contracts articles
An Oracle in the context of a Blockchain, is a process which retrieves information from an external resource and registers it on the Blockchain. Other contracts or online users, can base decisions on this information. You can learn more about Oracles in this Coin Telegraph article.
As you recall from my previous articles Lightweight Contracts , Lightweight Contracts FAQ, and More Advanced Contracts, Ardor contracts are not executed by every node like Ethereum contracts. Instead, they are executed by one or more selected nodes. This makes the Ardor contracts ideal for Oracle implementation for loading information from external resources and recording it on the Blockchain.
See for example, the IgnisArdorRates contract which is part of the Ardor sample contracts. It helps identify arbitrage opportunities on the Ardor decentralized coin exchange by comparing the IGNIS per ARDR rate derived from the last trades on Bittrex with the last trades on the Ardor coin exchange.
The information retrieved by the contract, can be delivered using one of the following methods:
By setting an account property, which is automatically updated by the contract every 60 blocks (configurable).
As an encrypted message, sent back to any account which pays 1 IGNIS to the contract account.
Using an API call, which is available to the owner of the node which runs the contract.
Of course this sample contract can be enhanced in many ways, by providing configuration options for the currency pairs, by integrating with more exchanges, by looking into the current bid and ask orders instead of the last trades, and so on.
Since this contract is not executed by all nodes, it can freely interface with external resources, such as the Bittrex API, without preventing the Blockchain from reaching a consensus. Therefore, connecting to external resources no longer represents a risk for the whole network. In the worst case scenario, the Bittrex web site is down or works slowly causing the performance of the specific node running the contract to suffer, however, the rest of the nodes won’t be affected. It should be noted that this contract requires trust in the Oracle, in this case, Bittrex.
The contract also includes a unit test which tests all three methods of loading information from the contract (block, transaction, API call)
To summarize, Oracles provide a bridge between the Blockchain and external resources. The ability to develop and deploy them quickly and efficiently is essential for any smart contracts ecosystem. Ardor lightweight contracts provide a flexible and straightforward mechanism to develop Oracles which can interface with any external resource which offers an API interface, including resources which require authenticated access or even paid services.
Disclaimer: The lightweight contracts feature development is still evolving. Right now contracts can be deployed to the Ardor testnet.