4

I'm doing this to get all blocks from the network:

var web3 = new Web3();
web3.setProvider(new Web3.providers.IpcProvider("...", net));
web3.eth.subscribe('newBlockHeaders', function (err, result) {
    ...
}).on('data', function (blockHeader) {
    ...
});

but callbacks are never called (except when I shutdown Geth)

Using web3 1.0 and latest Geth on Windows and Linux.

Also tried with web sockets without luck. Is there something else I can try?

Thanks.

0

What worked for me is not to get the result from the on event, but get it in the callback:

web3.eth.subscribe('newBlockHeaders', function (err, result) {
    if(!error) {
        console.log(result); // succcess!
    }
});
| improve this answer | |
0

This works to me

let Web3 = require('web3')

const web3 = new Web3(new Web3.providers.WebsocketProvider('wss://xxxxxx'))

web3.eth.subscribe('newBlockHeaders', function (error, result) {    
    if (!error) {
        console.log(result);
    }
});
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.