Template for creating and managing on-chain/off-chain zap subscriber
Check out our Documentation for more information about zap subscriber
On-chain subscriber contract that bond, query and receive response from Oracles with callback
- SSubscriber.sol : This is your subscriber contract that will bond-query-receive response, change name and structure as you go, this only meant to be an example. Only function
callbackneed to be modified to add more custom logic of what to do with the responses received - ZapBridge: This contract includes all the neccessary Zap Contracts function calls that your subscriber contract needs to call, such as bond, delegate bond, query
- Fill out truffle config file with your wallet and node information
- Fill out
2_subscriber_migration.jsfile with information about Oracle and Endpoint to use - Implement function
callbackin SimpleSubscriber contract - Run
truffle compile,truffle migrateto start create/get Oracle and start listening to queries
- Ensure you have enough ETH and ZAP in your address
- Owner of contract can choose to call
approvedirectly from owner, and calldelegateBondfunction to bond contract to Oracle indirectly
After successfully deploy your subscriber contract on blockchain, start using your subscriber contracts with couple simple steps:
- Query provider (regarding to provided schema from provider)
Provider will call function
callbackof subscriber, depends on the logic in the function that will determines what to happen
Off-chain subscriber script that approve, bond, query and listen to response events from Oracle
- Put your custom information in Config.ts file
- Implement function
processResponseto add your custom logic there to process responses received
yarn buildyarn start-offchainOnce Oracle response , you will see response string logged out and passed into functionprocessResponse