web3.onChange
Wondering how often / when you should call Web3 methods again to refresh the content?
Usage
Install:
$ npm install web3.onChange --save
Use:
;; // Initialize web3let web3 = typeof web3 === 'undefined' ? 'http://localhost:8545' : web3; // Install .onChange pluginweb3 = Web3OnChange; // Instead of:; // Just do:const off = web3ethgetBalance;// To stop watching:; // Same with contracts:const off2 = web3ethbalance;
How it works
By default all queries are made (batched) for each new block. It is planned to support other polling schemes in future.
TODO
- - Support time-based polling (
.onChange(...args, callback, 500)
- would poll every 500s) - - Support jacogr/ethapi-js
- - Support pending-transactions polling (
.onChange(...args, callback, 'pending')
) - - Support Filter/Logs polling?