Using JSON-RPC APIs¶
Programmatically interfacing geth nodes¶
As a developer, sooner rather than later you’ll want to start interacting with geth and the Ethereum Classic network via your own programs and not manually through the console. To aid this, geth has built-in support for a JSON-RPC based APIs (standard APIs and geth specific APIs). These can be exposed via HTTP, WebSockets and IPC (UNIX sockets on UNIX based platforms, and named pipes on Windows).
The IPC interface is enabled by default and exposes all the APIs supported by geth, whereas the HTTP and WS interfaces need to manually be enabled and only expose a subset of APIs due to security reasons. These can be turned on/off and configured as you’d expect.
HTTP based JSON-RPC API options:
--httpEnable the HTTP-RPC server--http.addrHTTP-RPC server listening interface (default:localhost)--http.portHTTP-RPC server listening port (default:8545)--http.apiAPI’s offered over the HTTP-RPC interface (default:eth,net,web3)--http.corsdomainComma separated list of domains from which to accept cross origin requests (browser enforced)--wsEnable the WS-RPC server--ws.addrWS-RPC server listening interface (default:localhost)--ws.portWS-RPC server listening port (default:8546)--ws.apiAPI’s offered over the WS-RPC interface (default:eth,net,web3)--ws.originsOrigins from which to accept websockets requests--graphqlEnable GraphQL on the HTTP-RPC server. Note that GraphQL can only be started if an HTTP server is started as well.--graphql.corsdomainComma separated list of domains from which to accept cross origin requests (browser enforced)--graphql.vhostsComma separated list of virtual hostnames from which to accept requests (server enforced). Accepts ‘*’ wildcard. (default: “localhost”)--ipcdisableDisable the IPC-RPC server--ipcapiAPI’s offered over the IPC-RPC interface (default:admin,debug,eth,miner,net,personal,shh,txpool,web3)--ipcpathFilename for IPC socket/pipe within the datadir (explicit paths escape it)
You’ll need to use your own programming environments’ capabilities (libraries, tools, etc) to connect via HTTP, WS or IPC to a geth node configured with the above flags and you’ll need to speak JSON-RPC on all transports. You can reuse the same connection for multiple requests! Here you can check the available JSON-RPC calls.
Attention
Please understand the security implications of opening up an HTTP/WS based transport before doing so! Hackers on the internet are actively trying to subvert Ethereum nodes with exposed APIs! Further, all browser tabs can access locally running web servers, so malicious web pages could try to subvert locally available APIs!