Hi,
I’m trying to subscribe “newheads” with using web3 on node.js.
But Error message “Subscription “newHeads” doesn’t exist. Subscribing anyway.” is returned.
However I can get the response of newBlockHeader.
Is this behavior properly?
The message “Subscription “newHeads” doesn’t exist” confuses me.
Because I get the correct response despite the error message being sent.
My code is here.
‘use strict’;
const Web3 = require(‘web3’);
let web3 = new Web3(new Web3.providers.WebsocketProvider(‘wss://mainnet.infura.io/ws/v3/MY_ID’));
const webSocketTest = async () => {
let subscription = web3.eth.subscribe(“newHeads”, function (error, result) {})
.on(“data”, function (block) {
console.log(block);
});
};webSocketTest();
This may be a simple question, but I’m newbie of programer.
I would appreciate it if you could reply.
node.js: v14.3.0
web3: 1.2.11