This example implements 2 contracts and 2 behaviours- client-side and server-side.
Client asks for the data (in our case - simply hardcoded exchange rates), the server, which uses oracles to provide an information (currently hardcoded).
When server contract is deployed, contract's address will be registered as an oracle in Aeternity blockchain. The information(in our case - exchange rates) and contracts key are also initialized and stored at the time of contract initialization. Server makes validations of the request and returns a requested data.
Ensure that you have installed forgAE project
forgae deploy
This command will deploy the contract in the local network.
The configuration of deployment is written in deploy.js
file.
forgae test
All tests should be passing.
get_exchange_rate(oracle_interface, currency)
- the function takes 2 arguments -oracle_interface
which is the server-side contract's address andcurrency
which is the name of currency. The return type of this function is astring
.
get_oracle_address()
- the function which returns the oracle address. Return type isAddress
.process_response(oracle, query)
- the function starts processing user's request,oracle
is the key of the oracle, registered in a state of the server's contract and thequery
which is a request to the server. Return type isstring
.