0

I am trying to get the way to register subscriptions to events, with the services of QuikNode I can do it without problem and it is working perfect, but I am trying to raise a node --light with geth or with parity, I have tried both and none works subscribe to events code, simply display a message that says: connection not open on send, also shows this other error: stack: "Error: connection not open \ n at WebsocketProvider.send

code that i am using: (how can i subscribe those events as i do in infura or QuikNode ?)

const ws_Provider = new 
Web3.providers.WebsocketProvider("ws://127.0.0.1:8546", {
 headers: {
      Origin: "http://localhost"

   }
 });
web3 = new Web3(ws_Provider);



function subscribsEth(){

var web3nsk = new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:8545"))

var subscription = web3.eth.subscribe('pendingTransactions',function(error, result){

    if(!error){

        web3nsk.eth.getTransaction(result,function(err,tx){
            if(!err && tx != null && tx.to != null && tx.from != null && tx.hash != null && tx.value != null){
                verifyKeyDB(tx.to, tx.from, tx.hash, tx.value, 3);                     
            }else{
                var datesNow = new Date();
                var lastNow = "0"+(datesNow.getUTCMonth() + 1)+ "/"+ datesNow.getUTCDate()+ " - Time: "+ datesNow.getUTCHours()+ ":"+ datesNow.getMinutes()+ ":"+ datesNow.getSeconds();

                console.log("subscribsETH: "+err + " - " + lastNow);
            }
        })
    }
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.