I'm trying to subscribe to newBlockHeaders
on the ropsten network, but it does not seem to work. The following code works for mainnet but not ropsten. Any ideas?
const Web3 = require('web3')
const webSocketProvider = new Web3.providers.WebsocketProvider(
'wss://ropsten.infura.io/ws/v3/<MY PROJECT ID>'
)
const web3 = new Web3(webSocketProvider)
async function notify() {
var subscription = web3.eth
.subscribe('newBlockHeaders', async function (error, result) {
if (!error) {
console.log(result)
return
}
console.error(error)
})
.on('connected', function (subscriptionId) {
console.log('Connected!')
})
.on('error', console.error)
}
notify()