Offchain Subscriber Example
Example of off chain subscriber to listen to data received from Oracles
What's off-chain Subscriber ?
Off-chain subscriber is non-contract method to query Endpoints and receive data through events from Oracle. It can be a script to query and react on the response received from Oracles through Ethereum blockchain events
or users can manually query and wait to see responses using zap-term cli tool
Template
Following script includes calling query and waiting for response events
Subscriber template provide a class that you can setup the function processResponse
much as on-chain subscriber implementing callback
function. That will be all you need to do to have fully functional off-chain subscriber
Using Template
Source Code : https://github.com/zapproject/subscriber-template.git
Setup environment and create off-chain subscriber
cd
subscriber-template
cd
Offchai_Subscriber_Example
Fill out config file variables such as mnemonic, oracle address, endpoint, query, dots ...
In
Simplesubscriber.ts
, fill out the body of functionprocessMessage
Make sure you have ZAP and ETH balances in your mnemonic's address
yarn
yarn build
yarn start-offchain
You can modify the index.ts
file to include logic when to trigger the query to Oracle
That's it, now you have a Zap Subscriber that interact with Zap contracts and Oracles to receive data you need.
Last updated