ganache-cli can't return accounts info via websocket

Created on 28 Nov 2018  路  2Comments  路  Source: trufflesuite/ganache-cli


ganache-cli can't return accounts info via websocket

  • I asked about this on gitter: [x]

Expected Behavior

return the accounts info of the ganache-cli server.

Current Behavior

ganache-cli server crashed with the following stack:

TypeError: connection.reject is not a function
    at WebSocketConnection.<anonymous> (C:\Users\shwj\AppData\Roaming\npm\node_modules\ganache-cli\node_modules\ganache-core\lib\webSocketServer.js:49:18)
    at emitOne (events.js:116:13)
    at WebSocketConnection.emit (events.js:211:7)
    at WebSocketConnection.processFrame (C:\Users\shwj\AppData\Roaming\npm\node_modules\ganache-cli\node_modules\ganache-core\node_modules\websocket\lib\WebSocketConnection.js:529:26)
    at C:\Users\shwj\AppData\Roaming\npm\node_modules\ganache-cli\node_modules\ganache-core\node_modules\websocket\lib\WebSocketConnection.js:321:40
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

Possible Solution

Websocket request handler issue.

Steps to Reproduce (for bugs)

  1. start ganeche-cli using command
ganache-cli --account 0x0afd7091ee9e4dc73aa75ac00a4be3e5d1d475fa0c18d2b837372fe0ab2e392c,0xFFFFFFFFFFFFFFFFFF 0x96519d4e91b8c5056ac909fe19a6d6d58f45a9f03d31b7f2836c01af19a9a1d7,0xFFFFFFFFFFFFFFFFFF 0xd56a9fc3338826bb41e67b9975bd294833698de5800bc2377307800598458088,0xFFFFFFFFFFFFFFFFFF.
  1. writing test.py by using web3.py library:
import web3
from web3 import Web3
from solc import compile_source
def main():

    my_provider = Web3.WebsocketProvider('ws://127.0.0.1:8545')
    w3 = Web3(my_provider)
    print(w3.eth.accounts)
    return 
  1. run test.py.

Context

  • Comparing ganache-cli with infura.io under the same web3.py client . infrura.io can return the expected result whereas ganache-cli can't . I suppose it is a bug for ganache-cli.
  • BTW, if a send a ws request using raw websocket client like the ws client plugin in chrome , it worked:
    I sent
{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}

and got the correct result :
image

Your Environment

  • Version used: ganache-cli : V6.2.1 (ganache-core:2.3.1)
  • Version of Truffle/Remix/Other tools used: * web3.py : 4.8.1
  • NodeJS Version: [ ] 6.x, [ ] 7.x (unsupported), [ ] 8.x, [x] 9.x
  • Operating System and version (include distro if Linux): win7 ultimate
  • Link to your project or repro gist:
  • Commit hash to use with above link for reproduction:
  • I intend to submit a pull request to fix this issue: []
bug consistenccorrectness priority-high stability

All 2 comments

Thanks for reporting this, @ppLorins. I was able to reproduce the issue.

Two things are happening here:

  • Ganache doesn't currently support binary over websockets, which is what web3.py sends (instead of UTF8 encoded JSON). So when we attempt to parse the incoming data we fail and throw an exception.
  • We do catch the exception then attempt to communicate to the caller that the request was a bad request, but the method we are attempting to call to do this doesn't exist, which causes ganache to crash.

We'll fix this by:

  1. supporting binary data in websocket messages
  2. fix our catch so it returns a proper jsonrpc 2.0 error response (with code: -32600) and a relevant error message.

Thanks again

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dwalintukan picture dwalintukan  路  6Comments

axic picture axic  路  5Comments

zweicoder picture zweicoder  路  3Comments

kumavis picture kumavis  路  3Comments

xavierlepretre picture xavierlepretre  路  5Comments