I tried code from web3js docs , but it didnt woork for me. I dont get any logs. Any idea why?

code i used:

    var subscription = web3.eth.subscribe('syncing', function(error, sync){
    if (!error)
    .on("data", function(sync){
    .on("changed", function(isSyncing){
        if(isSyncing) {
        } else {
            console.log("changed to false");


geth  --testnet --rpcapi "eth,web3, personal, accounts, miner, admin" --rpccorsdomain='*' --rpc --rpcaddr="" --rpcport "8545" --ws --wsorigins="*" --wsaddr --fast


let web3 =  new Web3(new Web3.providers.HttpProvider("ws://geth:8546"));

web3 version:

"web3": "^1.0.0-beta.30"

Blochchain is fully sinced.

  • I don't see you handling the error propperly, try with var subscription = web3.eth.subscribe('syncing', function(error, sync){ if (error != null) console.log(error); and report if any error appeared. – Nikita Fuchs Feb 21 '18 at 16:15

I believe you will have to change "ws://geth:8546" because you are passing websocket when it is expecting an HttpProvider.

Try changing .HttpProvider to .WebsocketProvider :

 let web3 =  new Web3(new web3.providers.WebsocketProvider("ws://geth:8546"));

Let me know if this worked out for you.

| improve this answer | |

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.