Oracle Template
Introduction
Zap-oracle-template provides an almost-ready code to have your Oracle and Endpoint setup and running from ground up in couple simple steps.
There are only 2 components to be filled out : Config.ts and Responder.ts and the template will perform all neccessary step to register Oracle, create Endpoint, Set parameters, even save information about Endpoint to ipfs and save the hash to Oracle's params to be displayed in Oracle Market Cap or Zap Admin site. Giving Oracle more visibility to users. ( If you have existing Oracle and Endpoint, this step will automatically ignored)
After creating and setting up Oracle and Endpoint, template code will start listening to queries, get data with logic in Responder.ts
and automatically respond to query.
Upon completing setup and run, you will have an Oracle that provides data without any manual management .
INSTALLATION
Set up oracle directory
SETUP
Config
Config.ts is where you configure your oracle, if you have not already done so in Zap-term or Zap Admin. If you haven't already initialized your oracle, config.ts is where Oracle.ts it gets its information to set up the current working Oracle. It requires the Oracle Title, public key, node websocket link, and the mnemonic for the address running the Oracle
Oracle.ts
There should be very few reasons to edit Oracle.ts, although it is something you can edit if editing Config.ts is not enough. Oracle.ts initializes your Oracle and endpoints if they haven't been already, and it runs your Oracle endpoints as if they have been given functionality. It parses incoming events from the Zap contracts and returns responses to them, allowing for subscribers to query your oracle.
Responder.ts
This is the area where you should place your oracle functionality. You can assume that the event parameter always has the same kind of key:value data. From the event you can parse out the query and the endpoint parameters in order to form a response, which should be in an array of either strings, integers, or bytes32.
RUNNING ORACLE
Congratulations, you have successfully created an oracle and start listening to query as well as providing responses to subscribers. Make sure to leave it running as a daemon, as it will only respond to queries while it is running.
Last updated