I am on web3 version 1.0.0-beta.27 and I am running a private ethereum blockchain for testing purposes. The blockchain is mining and has two users, now I would like to subscribe to events in the blockchain and perform some actions. The code is below:
var Web3 = require("web3");
var ether_port = 'http://localhost:8545'
var web3 = new Web3(new Web3.providers.HttpProvider(ether_port));
web3.eth.subscribe("pendingTransactions"
, function(err, result){
if (err){ console.log(err) }
else { console.log("result: ", result) }
});
I get something like:
Error: The current provider doesn't support subscriptions: HttpProviderat Subscription. subscribe
In some sense not surprising since when I do web3.eth.subscribe on the node.js console I get:
{ [Function] call: undefined }
Even though the documentation for web3-1.0.0 states the function can be used: https://web3js.readthedocs.io/en/1.0/web3-eth-subscribe.html.
So is this just a matter of documentation being out of sync with actual implementation? Am I using it wrong?
If it is not implemented, what is the best way to listen to changes in the chain? For example, if I want a real-time update of a user's account balance? That is aside from the naive implementation of a function that pings the chain every n fraction of a second.