Subscription event fired on each new block.
Nothing.
(async function () {
var Web3 = require("web3");
var web3 = new Web3("ws://localhost:8546");
console.log("Web3 Version: ", web3.version);
var latestBlock = await web3.eth.getBlock("latest");
console.log("Latest Block: ", latestBlock.number);
var subscription = web3.eth.subscribe("newBlockHeaders");
subscription.on("data", function (blockHeader) {
console.log("Got block: ", blockHeader.number);
});
})();
This will work as expected up to and including 1.0.0-beta.37. In the latest version (beta-41) nothing happens - no error, no events.
No errors logged.
I've tested it locally and can't reproduce this behavior. Which node type are you using? (Parity, Geth, Ganache)

Latest parity beta:
lth@ncpws04:~$ parity --version
Parity Ethereum
version Parity-Ethereum/v2.3.2-beta-678138f-20190203/x86_64-linux-gnu/rustc1.31.1
Copyright 2015-2018 Parity Technologies (UK) Ltd.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
By Wood/Paronyan/Kotewicz/Drwi臋ga/Volf
Habermeier/Czaban/Greeff/Gotchac/Redmann
Private POA chain with block every 5 seconds. Subscription with beta.37 works fine.
Actually I have a public node running. Try this - it works with beta.37 but fails with beta.43 (which by the way reports itself as 42):
/*
* Web3 Websocket Test
*/
(async function () {
var Web3 = require("web3");
var web3 = new Web3("wss://devchain.subutai.io:8546");
console.log("Web3 Version: ", web3.version);
var latestBlock = await web3.eth.getBlock("latest");
console.log("Latest Block: ", latestBlock.number);
web3.eth.subscribe("newBlockHeaders")
.on("data", function (blockHeader) {
console.log("Got block: ", blockHeader.number);
});
web3.eth.subscribe("pendingTransactions")
.on("data", function (tx) {
console.log("Pending tx: ", tx);
});
})();
/*
* vim: ts=4 et nowrap autoindent
*/
Those nodes run:
Parity Ethereum
version Parity-Ethereum/v2.3.0-beta-10657d9-20190115/x86_64-linux-gnu/rustc1.31.1
Copyright 2015-2018 Parity Technologies (UK) Ltd.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
By Wood/Paronyan/Kotewicz/Drwi臋ga/Volf
Habermeier/Czaban/Greeff/Gotchac/Redmann
Notice that the wss connection works (latest block reported in both cases) only subscription fail with beta 43.
@lbthomsen Thanks for the detailed information I will have a look at it today!
Just for the sake of complete info - Debian stretch with node ver. 10.15.1
Confirmed fixed in beta.44
There is still an issue with the callback
In 1.0.0-beta.51 if you omit the EventEmitters and just use the callback, the callback is never fired
Callback should be removed or fixed?
const subscription = web3.eth.subscribe('newBlockHeaders', function(error, result){
if (!error) {
console.log(result);
return;
}
console.error(error);
})
Also one minor thing, the Subscription.on methods in the typings indicate it returns void however i believe this should be
on(type: 'data', handler: (data: T) => void): Subscription