2019-11-05 06:46:00 -06:00
|
|
|
---
|
|
|
|
title: JSON-RPC Server
|
|
|
|
sort_key: A
|
|
|
|
---
|
|
|
|
|
|
|
|
Geth supports all standard web3 JSON-RPC APIs. You can find documentation for
|
2019-12-04 09:01:29 -06:00
|
|
|
these APIs on the [Ethereum Wiki JSON-RPC page][web3-rpc].
|
2019-11-05 06:46:00 -06:00
|
|
|
|
|
|
|
JSON-RPC is provided on multiple transports. Geth supports JSON-RPC over HTTP,
|
|
|
|
WebSocket and Unix Domain Sockets. Transports must be enabled through
|
|
|
|
command-line flags.
|
|
|
|
|
|
|
|
Ethereum JSON-RPC APIs use a name-space system. RPC methods are grouped into
|
|
|
|
several categories depending on their purpose. All method names are composed of
|
|
|
|
the namespace, an underscore, and the actual method name within the namespace.
|
|
|
|
For example, the `eth_call` method resides in the `eth` namespace.
|
|
|
|
|
|
|
|
Access to RPC methods can be enabled on a per-namespace basis. Find
|
|
|
|
documentation for individual namespaces in the sidebar.
|
|
|
|
|
|
|
|
### HTTP Server
|
|
|
|
|
2020-09-10 07:21:13 -05:00
|
|
|
To enable the HTTP server, use the `--http` flag.
|
2019-11-05 06:46:00 -06:00
|
|
|
|
2020-09-10 07:21:13 -05:00
|
|
|
geth --http
|
2019-11-05 06:46:00 -06:00
|
|
|
|
|
|
|
By default, geth accepts connections from the loopback interface (127.0.0.1).
|
|
|
|
The default listening port is 8545. You can customize address and port using the
|
2020-09-10 07:21:13 -05:00
|
|
|
`--http.port` and `--http.addr` flags.
|
2019-11-05 06:46:00 -06:00
|
|
|
|
2020-09-10 07:21:13 -05:00
|
|
|
geth --http --http.port 3334
|
2019-11-05 06:46:00 -06:00
|
|
|
|
|
|
|
JSON-RPC method namespaces must be whitelisted in order to be available through
|
2020-02-21 07:06:20 -06:00
|
|
|
the HTTP server. An RPC error with error code `-32602` is generated if you call a
|
|
|
|
namespace that isn't whitelisted. The default whitelist allows access to the "eth"
|
|
|
|
and "shh" namespaces. To enable access to other APIs like account management ("personal")
|
2020-09-10 07:21:13 -05:00
|
|
|
and debugging ("debug"), they must be configured via the `--http.api` flag. We do
|
2019-11-05 06:46:00 -06:00
|
|
|
not recommend enabling such APIs over HTTP, however, since access to these
|
|
|
|
methods increases the attack surface.
|
|
|
|
|
2020-10-16 02:30:14 -05:00
|
|
|
geth --http --http.api personal,eth,net,web3
|
2019-11-05 06:46:00 -06:00
|
|
|
|
|
|
|
Since the HTTP server is reachable from any local application, additional
|
|
|
|
protection is built into the server to prevent misuse of the API from web pages.
|
|
|
|
If you want enable access to the API from a web page, you must configure the
|
2020-09-10 07:21:13 -05:00
|
|
|
server to accept Cross-Origin requests with the `--http.corsdomain` flag.
|
2019-11-05 06:46:00 -06:00
|
|
|
|
2019-12-04 09:01:29 -06:00
|
|
|
Example: if you want to use [Remix][remix] with geth, allow requests from the
|
2019-11-05 06:46:00 -06:00
|
|
|
remix domain.
|
|
|
|
|
2020-09-10 07:21:13 -05:00
|
|
|
geth --http --http.corsdomain https://remix.ethereum.org
|
2019-11-05 06:46:00 -06:00
|
|
|
|
2020-09-10 07:21:13 -05:00
|
|
|
Use `--http.corsdomain '*'` to enable access from any origin.
|
2019-11-05 06:46:00 -06:00
|
|
|
|
|
|
|
### WebSocket Server
|
|
|
|
|
|
|
|
Configuration of the WebSocket endpoint is similar to the HTTP transport. To
|
|
|
|
enable WebSocket access, use `--ws` flag. The default WebSocket port is 8546.
|
2020-09-10 07:21:13 -05:00
|
|
|
The `--ws.addr`, `--ws.port` and `--ws.api` flags can be used to customize settings
|
2019-11-05 06:46:00 -06:00
|
|
|
for the WebSocket server.
|
|
|
|
|
2020-09-10 07:21:13 -05:00
|
|
|
geth --ws --ws.port 3334 --ws.api eth,net,web3
|
2019-11-05 06:46:00 -06:00
|
|
|
|
|
|
|
Cross-Origin request protection also applies to the WebSocket server. Use the
|
2020-09-10 07:21:13 -05:00
|
|
|
`--ws.origins` flag to allow access to the server from web pages:
|
2019-11-05 06:46:00 -06:00
|
|
|
|
2020-09-10 07:21:13 -05:00
|
|
|
geth --ws --ws.origins http://myapp.example.com
|
2019-11-05 06:46:00 -06:00
|
|
|
|
2020-09-10 07:21:13 -05:00
|
|
|
As with `--http.corsdomain`, using `--ws.origins '*'` allows access from any origin.
|
2019-11-05 06:46:00 -06:00
|
|
|
|
|
|
|
### IPC Server
|
|
|
|
|
|
|
|
JSON-RPC APIs are also provided on a UNIX domain socket. This server is enabled
|
|
|
|
by default and has access to all JSON-RPC namespaces.
|
|
|
|
|
2020-02-27 04:04:39 -06:00
|
|
|
The listening socket is placed into the data directory by default. On Linux and macOS,
|
|
|
|
the default location of the geth socket is
|
2019-11-05 06:46:00 -06:00
|
|
|
|
|
|
|
~/.ethereum/geth.ipc
|
|
|
|
|
2020-02-27 04:04:39 -06:00
|
|
|
On Windows, IPC is provided via named pipes. The default location of the geth pipe is:
|
|
|
|
|
|
|
|
\\.\pipe\geth.ipc
|
|
|
|
|
2019-11-05 06:46:00 -06:00
|
|
|
You can configure the location of the socket using the `--ipcpath` flag. IPC can
|
|
|
|
be disabled using the `--ipcdisable` flag.
|
|
|
|
|
|
|
|
[web3-rpc]: https://github.com/ethereum/wiki/wiki/JSON-RPC
|
|
|
|
[remix]: https://remix.ethereum.org
|