Websockets + Web3: `Error: Connection not open`
Closed this issue · 3 comments
emizzle commented
System information
Lightchain version: Version: 1.1.0-beta MainNet (but running off fork https://github.com/0x13a/lightchain/tree/fix/upgrade-geth)
OS & version: OSX Mojave 10.14.4 / Kernel Version 18.5.0
Go version: go version go1.12.5 darwin/amd64
Branch: https://github.com/0x13a/lightchain/tree/fix/upgrade-geth
Commit hash: cb8e32e6209e8aaf302ac21d67cabe014b667b3e
Expected behaviour
Lightchain works fine with the Web3 HTTP provider, but with websockets, I cannot seem to open a connection.
I noticed there is no CLI option for --wsapi
, is this on purpose?
web3.eth.getAccounts().then(console.log).catch(console.error)
Should return
[ '0xc916Cfe5c83dD4FC3c3B0Bf2ec2d4e401782875e' ]
Actual behaviour
Error: connection not open
at WebsocketProvider.send (/Users/emizzle/temp/lightstreams-js-sdk/node_modules/web3-providers-ws/src/index.js:276:18)
at RequestManager.send (/Users/emizzle/temp/lightstreams-js-sdk/node_modules/web3-core-requestmanager/src/index.js:132:66)
at sendRequest (/Users/emizzle/temp/lightstreams-js-sdk/node_modules/web3-core-method/src/index.js:560:42)
at Eth.send [as getBalance] (/Users/emizzle/temp/lightstreams-js-sdk/node_modules/web3-core-method/src/index.js:581:13)
at repl:1:10
at Script.runInThisContext (vm.js:91:20)
at REPLServer.defaultEval (repl.js:317:29)
at bound (domain.js:396:14)
at REPLServer.runBound [as eval] (domain.js:409:12)
at REPLServer.onLine (repl.js:615:10)
at REPLServer.emit (events.js:187:15)
at REPLServer.EventEmitter.emit (domain.js:442:20)
at REPLServer.Interface._onLine (readline.js:290:10)
at REPLServer.Interface._line (readline.js:638:8)
at REPLServer.Interface._ttyWrite (readline.js:919:14)
at REPLServer.self._ttyWrite (repl.js:688:7)
at ReadStream.onkeypress (readline.js:168:10)
at ReadStream.emit (events.js:182:13)
at ReadStream.EventEmitter.emit (domain.js:442:20)
at emitKeys (internal/readline.js:422:14)
at emitKeys.next (<anonymous>)
at ReadStream.onData (readline.js:1022:36)
Steps to reproduce the behaviour
lightchain init --force --standalone
lightchain run --rpc --rpcport=8555 --rpcaddr=localhost --rpcapi=eth,web3,net,debug,personal,shh --ws --wsport=8556 --wsaddr=localhost
In a new term:- Install web3 beta 37:
npm install web3@1.0.0-beta.37
- Start a REPL:
node
let web3 = new Web3(new Web3.providers.WebsocketProvider("ws://localhost:8556"))
NOTE: I have also triedlet web3 = new Web3(new Web3.providers.WebsocketProvider("ws://127.0.0.1:8556"))
because the run routine output shows the websocket endpoint asws://127.0.0.1:8556
:
INFO [05-16|11:43:22.533] IPC endpoint opened url=/Users/emizzle/.lightchain/database/geth.ipc
INFO [05-16|11:43:22.682] HTTP endpoint opened url=http://localhost:8555 cors= vhosts=localhost
INFO [05-16|11:43:22.686] WebSocket endpoint opened url=ws://127.0.0.1:8556
web.eth.getAccounts().then(console.log).catch(console.error)
Error: connection not open
(see stack above)
This works with HTTP:
lightchain init --force --standalone
lightchain run --rpc --rpcport=8555 --rpcaddr=localhost --rpcapi=eth,web3,net,debug,personal,shh --ws --wsport=8556 --wsaddr=localhost
In a new term:- Install web3 beta 37:
npm install web3@1.0.0-beta.37
- Start a REPL:
node
let web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8555"))
web.eth.getAccounts().then(console.log).catch(console.error)
[ '0xc916Cfe5c83dD4FC3c3B0Bf2ec2d4e401782875e' ]
ggarri commented
As you metioned, there is no currently support for --wsapi
and --wsorigins
and that is the reason of that issue.
We just did some quick work to support them. I reproduced the same scenario you describe above with web3 and it works after the changes applied to this PR
Along the today we are planning to merge this into master and publish a new version.
Thanks for pointing this out! :)