5

Running geth with websocket:

geth --fast --cache=512 --ws --wsorigins="*" --wsapi "db,eth,net,ssh,miner,web3,personal,admin"

Then connecting with web3 in a Node.js app:

const Web3 = require('web3');

var web3 = new Web3(new Web3.providers.WebsocketProvider("ws://localhost:8546"));

console.log(web3.version);

web3.eth.subscribe('pendingTransactions', function(err, res) {
    console.log('Here')
    console.log(err)
    console.log(res)
}).on('data', function(transaction) {
    console.log('Here 2')
    console.log(transaction)
});

"Here", "Here 2" do not print to the console. The subscription does not seem to activate. web3.version and other web3 commands work fine.


Geth version: 1.7.1-stable

Web3 version: 1.0.0-beta.22

1

Please make sure you are synced up. While geth is doing its fast sync, the chain is incomplete, so there aren't any events being fired, since there's no existing events yet. Only when the chain sync fully will events start appearing.

0

You are trying to get the pending transaction so event may not be fired, the event only get fired when transaction mined successful, in your case the chain will always be incomplete as you are only calling pending transaction

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.