2

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)
        console.log(sync);
})
    .on("data", function(sync){
        console.log(sync);
    })
    .on("changed", function(isSyncing){
        if(isSyncing) {
            console.log("changed");
        } else {
            console.log("changed to false");
        }
    });

geth:

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

web3:

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
3

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.