0

I'm trying to programmatically connect to a JavaScript console (just like you get with geth attach) using the geth.ipc file that gets created in the chaindata folder. On Linux, it's a socket file, so I figured I could connect to it with something like this (in Python):

import socket

client = socket.socket( socket.AF_UNIX, socket.SOCK_STREAM )
client.connect("/home/john/Desktop/EthPrivateChain/chaindata/geth.ipc")

client.send(str.encode("admin.nodeInfo.enode"))
print(str(client.recv(1024)))

client.close()

However, this gives me the JSON RPC, not the JavaScript console. The code works but the endpoint returns an error when I try this. The same code, but with a JSON request, works. I want the JavaScript console because I want to be able to access some stuff that isn't available through the JSON RPC, specifically the enode in this case. I think there has to be a way to connect to that file this way because I can use it to start a console with geth attach /home/john/Desktop/EthPrivateChain/chaindata/geth.ipc. Is there some way I can make this socket file access the JavaScript API when I access it with my own code?

2

The command geth attach only creates its own javascript read-eval-loop, but still uses JSON-RPC commands to talk with geth node through the ipc file.

Geth provides a sets of more advanced commands that are only accessible using JSON-RPC that are geth only Management APIs.

Some of this APIs can be accessed from javascript with web3Admin.

  • For anyone else trying to do this, the management API documentation says that you need to explicitly enable these APIs in the command line when you start Geth, but I didn't have to. They were enabled by default in Geth 1.7.3. – John Stanford Feb 1 '18 at 5:13
  • 1
    @JohnStanford They are enabled by default if you use IPC, but you need to explicitely enable them if you use the RPC interface. – Ismael Feb 1 '18 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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