18

I'm running parity with the --jsonrpc flag which listens on port 8545 by default.

I'm trying to attach a geth instance, like described in the the docs:

Attach a console to a running geth instance. By default this happens over IPC on the default IPC endpoint but when necessary a custom endpoint could be specified:

geth attach                   # connect over IPC on default endpoint
geth attach ipc:/some/path    # connect over IPC on custom endpoint
geth attach http://host:8545  # connect over HTTP
geth attach ws://host:8546    # connect over websocket

But I get a fatal error:

Fatal: Unable to attach to geth node - Invalid endpoint

This is my tested commands:

 ~ $ geth attach http://127.0.0.1:8545
Fatal: Unable to attach to geth node - Invalid endpoint
 ~ $ geth attach http://localhost:8545
Fatal: Unable to attach to geth node - Invalid endpoint
 ~ $ geth attach ws://localhost:8545
Fatal: Unable to attach to geth node - Invalid endpoint

How to attach geth to a local RPC on port 8545?

3 Answers 3

10

#Via Geth:

When you run your Parity node, use the --geth flag, for example, parity --geth.

Then go into another window and run geth attach.

The output of this is:

Welcome to the Geth JavaScript console!
>

The great thing about Parity is that you don't need to worry about turning on JSON-RPC, as it's on by default.

#Via Node:

Another approach is to use the NodeJS web3 library, which provides the same functionality. From Parity Quick Start:

npm install web3
node # Enter REPL
Web3 = require("web3");
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

Now you can interact with Parity the same as the Javascript Console:

web3.eth.getBlockNumber().then(blockNumber => console.log(blockNumber)) // Regular Geth command, except connected to Parity
743397
3
  • Nice, --geth did the trick.
    – q9f
    Commented Jul 3, 2016 at 11:39
  • for web3 1.0.0 : web3.eth.isSyncing().then(console.log)
    – Karan
    Commented Dec 2, 2018 at 12:02
  • most web3 command returns promises : so print callback res
    – Karan
    Commented Dec 2, 2018 at 12:03
7

Recently released version 1.1 of Parity supports modules/rpc_modules RPC method and allows you to geth attach <rpcaddress> (geth 1.3.6 and 1.4.0 are supported).

Release details: https://blog.ethcore.io/announcing-parity-1-1/

Examples:

Geth 1.3.6

$ geth attach rpc://localhost

Geth 1.4.0

$ geth attach http://localhost:8545

3
  • Hum, Fatal: Unable to attach to geth node - dial unix /home/user/.ethereum/geth.ipc: connect: connection refused. Seems not ready yet.
    – q9f
    Commented May 4, 2016 at 10:10
  • You need to specify HTTP rpc endpoint: geth attach rpc://localhost 1.3.6 or geth attach http://localhost:8545 1.4.0
    – todr
    Commented May 4, 2016 at 11:11
  • Feel free to use the edit button to improve your answer.
    – q9f
    Commented May 4, 2016 at 11:12
5

Summary

I don't think that you will be able to connect geth attach (version 1.3.6) to parity (version Parity/v1.0.2-beta/x86_64-linux-gnu/rustc1.7.0).



Details

I tested using geth attach to connect to parity --rpc and I got the following message

Fatal: Unable to initialize console - Unable to parse module response - <nil>

So I did a trace using tcpdump and the results follow.

I started parity with the following options:

parity --datadir datadir --rpc --rpcapi "web3,eth,net,personal"  --rpccorsdomain "*"

I started tcpdump using the following command (meaning dump data in ASCII format on the interface lo (127.0.0.1) and port 8545):

sudo tcpdump -A -i lo port 8545

I started geth using the following command:

geth attach rpc:http://127.0.0.1:8545

And here are the results from tcpdump (tidied):

IP localhost.38186 > localhost.8545
POST / HTTP/1.1
Host: 127.0.0.1:8545
User-Agent: Go-http-client/1.1
Content-Length: 57
Content-Type: application/json
Accept-Encoding: gzip

{"id":1,"jsonrpc":"2.0","method":"modules","params":null}

localhost.8545 > localhost.38186
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Tue, 26 Apr 2016 09:51:20 GMT
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Headers: origin, content-type, accept
Allow: OPTIONS, POST

{"jsonrpc":"2.0","error":{"code":-32601,"message":"Method not found","data":null},"id":1}

geth is asking parity for the support modules, but parity does not understand the "modules" command, so geth gives up.

I've tried using a few different options, but the results are similar.

I traced through the source code for geth and found that cmd/geth/js.go has a welcome() method that will request from the connected RPC instance what modules are supported. This is what you would normally see when you connect geth attach to geth --rpc:

    modules: db:1.0 eth:1.0 net:1.0 web3:1.0

But parity does not seem to support this JSON-RPC method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.