How to subscribe on blockchain events (web3)?
Hi, I have a problem with subscribing to blockchain events on web3.js library.
` const Web3 = require("web3"); const web3 = new Web3(new Web3.providers.WebsocketProvider("wss:my_link"));
web3.eth.subscribe("pendingTransactions", (err, result) => { if (err){ console.log(err) } else { console.log("result: ", result) } }); ` But as a result, I got an Error message - "error: no "newPendingTransactions" subscription in eth namespace". How can I fix this?
Chacked on many web3 versions, at this moment - 1.2.0
Thanks for attention.
Hi @maxprof. I have not been able to reproduce this on
- geth (local)
- ganache-cli (local)
- Infura (remote over wss)
Using the following script with Web3 1.2.6
Index.js
const Web3 = require('web3');
const util = require('util');
async function main(){
return new Promise(async function(resolve, reject){
const web3 = new Web3('wss://mainnet.infura.io/ws/v3/<my-infura-projectID>');
web3.eth.subscribe("pendingTransactions", (err, result) => {
if (err) return reject(err);
console.log(util.inspect(result));
resolve(result);
});
});
}
main()
.then(() => process.exit(0))
.catch(err => {
console.log(err);
process.exit(1);
})
Run
node index.js
> '0x2a1125b230f14d8c3f81f4287459bd67b59928493b2f45926738034279ed849f'
Which ethereum client / remote provider are you using in wss:my_link? It's possible they don't support the pending transactions endpoint.
@maxprof Closing because it's been a few days without response here and things seem like they're working as expected on Web3's side.
Please ping with more info if you'd like this re-opened.
i am facing this issue @cg
@maxprof Closing because it's been a few days without response here and things seem like they're working as expected on Web3's side.
Please ping with more info if you'd like this re-opened.
i am facing this issue @cgewecke did you manage to resolve this
I'm facing the same issue with private Geth node, anyone have a solution for this.