Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

web3.eth.subscribe not working #1093

Closed
johnnyboo opened this issue Oct 5, 2017 · 14 comments
Closed

web3.eth.subscribe not working #1093

johnnyboo opened this issue Oct 5, 2017 · 14 comments
Assignees
Labels
Bug Addressing a bug

Comments

@johnnyboo
Copy link

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, nothing is printed after the version prints to the console. web3.version and other web3 commands work fine.


Geth version: 1.7.1-stable

Web3 version: 1.0.0-beta.22

@er3es
Copy link

er3es commented Oct 19, 2017

I have the same issue. I don't get any messages for either pendingTransactions or newBlockHeaders subscriptions.

Geth version: 1.7.2-stable
Web3 version: 1.0.0-beta.23 ( and also 1.0.0-beta.24 )

@Lytigas
Copy link

Lytigas commented Oct 22, 2017

I don't receive any callbacks on any subscriptions either.
Web3 version: 1.0.0-beta.24
TestRPC 4.1.3

@er3es
Copy link

er3es commented Oct 22, 2017

@Lytigas @johnnyboo can you please try something for me? Connect using wscat to the socket and try these commands. Are you getting any notifications back? If not it might be an issue with geth and not web3.

@troystribling
Copy link

troystribling commented Oct 22, 2017

I have seen the same thing with [email protected] and [email protected].

@karalabe
Copy link
Contributor

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.

@raahil190
Copy link

I have the same issue - it dosn't seem to work on geth 1.7.2 (fast sync) - has anybody been able to resolve this yet ?

@LiorRabin
Copy link

same issue here -
geth version 1.7.2 (without fast sync)
web3 version 1.0.0-beta.24

wscat -c ws://some.host.com:8546
returns:

error: Error: unexpected server response (403)

@MrTibbles
Copy link

Have you ensured that you are passing --wsorigins, with the host you wish to use? As that 403 may be a failed handshake.

@LiorRabin
Copy link

@MrTibbles this is the command I'm running geth:
geth --rpc --ws --wsaddr 0.0.0.0 --wsorigins="*" --testnet --rpcaddr 0.0.0.0

@LiorRabin
Copy link

ok, so I've solved the issue running:

geth --rpc --rpccorsdomain="*" --ws --wsorigins="*" --wsaddr 0.0.0.0 --testnet --rpcaddr 0.0.0.0

Note: need to set BOTH rpccorsdomain & wsorigins

@MrTibbles
Copy link

Sorry, completely missed your initial response. I was close though, that being handshake failed :)

@LiorRabin
Copy link

@MrTibbles thanks for the help 👍

@shamoons
Copy link

shamoons commented May 10, 2018

Not working for me:

  const Web3 = require('web3');
  const web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.GETH_WS_URL));
  console.log(process.env.GETH_WS_URL);
  const syncSubscription = web3.eth.subscribe('syncing')
    .on('data', (tx) => {
      console.log('tx', tx);
    });

  console.log(syncSubscription);

I see here and the syncSubscription object, but nothing in the on('data

I'm launching with geth --rpc --syncmode fast --rpcaddr 0.0.0.0 --rpcapi web3,eth --ws --wsaddr 0.0.0.0 --wsapi web3,eth --wsorigins '*'

@nivida nivida self-assigned this Aug 9, 2018
@nivida nivida added the Bug Addressing a bug label Nov 29, 2018
@nivida
Copy link
Contributor

nivida commented Jan 22, 2019

This should be fixed with the PR #2000

@nivida nivida closed this as completed Feb 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Addressing a bug
Projects
None yet
Development

No branches or pull requests

10 participants