Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to use web sockets with web3 js. #14

Open
himanshuchawla009 opened this issue Mar 9, 2019 · 1 comment
Open

Not able to use web sockets with web3 js. #14

himanshuchawla009 opened this issue Mar 9, 2019 · 1 comment

Comments

@himanshuchawla009
Copy link

let nodeUrl = "wss://" + USER + ":" + PASS + "@" + WSS_ENDPOINT;

// let provider = new Web3.providers.WebsocketProvider(nodeUrl);
let web3 = new Web3(new Web3.providers.WebsocketProvider(nodeUrl))
// Now you can call web3 functions, so we'll just test the connection by getting the latest block in the chain.

web3.eth.getBlock("latest").then((latestBlock) => {
console.log("Latest Block Via Websocket Provider: ");
console.log(latestBlock);

}).catch((er)=>{
console.log("error",er)
})

This code snippet results in following error:-

http_outgoing.js:494
throw new TypeError('The header content contains invalid characters');
^

TypeError: The header content contains invalid characters
at validateHeader (_http_outgoing.js:494:11)
at ClientRequest.setHeader (_http_outgoing.js:498:3)
at new ClientRequest (_http_client.js:173:14)
at Object.request (http.js:38:10)
at Object.request (https.js:239:15)
at WebSocketClient.connect (/home/himanshu/kafkaTest/web3Listener/node_modules/websocket/lib/WebSocketClient.js:241:56)
at new W3CWebSocket (/home/himanshu/kafkaTest/web3Listener/node_modules/websocket/lib/W3CWebSocket.js:62:18)
at ProvidersModuleFactory.createWebsocketProvider (/home/himanshu/kafkaTest/web3Listener/node_modules/web3-providers/dist/web3-providers.cjs.js:1254:22)
at new WebsocketProvider (/home/himanshu/kafkaTest/web3Listener/node_modules/web3-providers/dist/web3-providers.cjs.js:1295:39)
at Object. (/home/himanshu/kafkaTest/web3Listener/index.js:98:22)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)

Same code snippet runs when i replace kaleido url with rinkeby websocket url of infura.

Please Help!!!

@himanshuchawla009 himanshuchawla009 changed the title Not able to use web sockets with web3. Not able to use web sockets with web3 js. Mar 9, 2019
@gmaijoe
Copy link

gmaijoe commented Apr 28, 2019

did you find a solution to this? i'm getting the same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants