Closed munawarb closed 6 years ago
testrpc does not support WebSockets, but it definitely should, since it doesn't support IPC either, and the HTTP provider doesn't support subscriptions anymore (since web3 1.0.0).
@onbjerg Do you know if there are any plans in the near future to support WebSockets?
@leopoldjoy I would assume yes, but there's no official word, so practically I don't know.
I opened up an issue about it in trufflesuite/ganache-core#11, as that is what they are using internally in testrpc.
$geth --datadir data --networkid 31415926 --ws --wsport 8546 --wsorigins "*" --rpc --rpcport 8545 --rpccorsdomain "*" --nodiscover console It works!!!
I'm not sure what you mean, that's geth, not testrpc.
why do they keep breaking the API?
This is a fast moving space. Everything should be expected to break. In this particular case, I actually think it's a pretty good idea not having long-lived connections over HTTP. 😊
The issue is that the ecosystem is pretty small, so keeping up with breaking changes is a bit of a hassle 😄
@munawarb Thanks for submitting this issue.
TestRPC does not as of yet support WebSocket connections, so I'm sad to say that this is expected behaviour. This is fairly high on my list of priorities for new features, but at the moment I'm focused on fixing up some defects. Once I get things a bit more stabilized, I'll dust off the old WebSockets PR and see what it'll take to get it merged.
@pannous I'm not sure what you were referring to when you mentioned breaking the API. In this case, there wasn't anything to break, as WebSockets are a feature which we have never supported (though per my last comment, I expect we'll have support for them before the end of the year). If we've inadvertently broken something, please do raise another issue.
Giveth relies on websockets so we use forked version of testrpc created by perissology: "ethereumjs-testrpc": "git://github.com/perissology/testrpc.git#81216dbc" This allows us to use websockets as expected (note changed port in our configs): "blockchain": { "nodeUrl": "ws://localhost:8546", "startingBlock": 0 }, You can see more about how we use it at https://github.com/Giveth/feathers-giveth
Starting a web3 connection like this:
var web3 = new Web3(new Web3.providers.WebsocketProvider("ws://localhost:8545"));
should open a websocket connection so I can consume events from the smart contract. I have testjs-rpc running like this:testrpc -m "hi"
Current Behavior
I get this error: /media/iot/nvme/ethereum/webap/node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/W3CWebSocket.js:111 throw new Error('cannot call send() while not connected'); ^
Error: cannot call send() while not connected at W3CWebSocket.send (/media/iot/nvme/ethereum/webap/node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/W3CWebSocket.js:111:15) at WebsocketProvider.send (/media/iot/nvme/ethereum/webap/node_modules/web3/packages/web3-providers-ws/src/index.js:209:21) at Timeout._onTimeout (/media/iot/nvme/ethereum/webap/node_modules/web3/packages/web3-providers-ws/src/index.js:200:19) at ontimeout (timers.js:469:11) at tryOnTimeout (timers.js:304:5) at Timer.listOnTimeout (timers.js:264:5)
Possible Solution
Steps to Reproduce (for bugs)
1. 2. 3. 4.
Context
I can't use HttpProvider because it's been deprecated and doesn't support event listening. So I'm trying to get a websocket thing going, but I'm unclear whether or not testjs-rpc supports it.
Your Environment