[Ethereum] How to attach geth to a local Parity RPC port 8545

go-ethereumjson-rpcparity

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?

Best Answer

#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
Related Topic