Geth 使用JSON数据格式, JSON-RPC协议做为客户端和网络进行交互的方法。 Geth 1.4 的 pub/sub 是实验性质的, 一样, Partity 1.6 也是。node
使用web3.js和etherenum节点交互时, 遵循一致的RPC协议.web
默认的JSON-RPC终端:json
Client URL跨域
C++ http://localhost:8545浏览器
GO http://localhost:8545网络
Py http://localhost:4000app
Parity http://localhost:8545cors
Godom
能够经过 --rpc 标志开启HTTP JSON-RPCcurl
geth --rpc
能够经过下面的方式修改默认的端口(8545)和地址(localhost):
geth --rpc --rpcaddr <ip> --rpcport <portnumber>
若是经过浏览器访问RPC, 须要注意跨域问题, 能够经过一下方式:
geth --rpc --rpccorsdomain "http://localhost:3000"
JSON-RPC也能够经过 geth console 开启, 以下:
admin.startRPC(addr, port)
C++
首先运行aleth启动节点:
build/aleth/aleth
而后开启JSON-RPC代理(默认 ~/.ethereum/geth.ipc 和 http://127.0.0.1:8545)
scripts/jsonrpcproxy.py
若是你使用非默认的IPC路径或者JSON-RPC, 能够指定:
scripts/jsonrpcproxy.py <path to your node's geth.ipc> <URL for this proxy server>
Python
在Python中, JSONRPC服务默认开启的端口和地址是127.0.0.1:4000
能够经过以下方式配置:
pyethapp -c jsonrpc.listen_port=4002 -c jsonrpc.listen_host=127.0.0.2 run
JSON-RPC 支持状况
cpp-ethereum :JSON-RPC 1.0 JSON-RPC 2.0 Batch requests HTTP IPC
go-ethereum :JSON-RPC 2.0 Batch requests HTTP IPC WS
py-ethereum :JSON-RPC 2.0 Batch requests HTTP
patity :JSON-RPC 2.0 Batch requests HTTP IPC WS
目前, 有2中主要的数据烈性用于JSON, unformatted byte arrays 和 quantities, 他们都是经过hex编码传递的。
下面的方法有一个额外的默认的block参数:
当请求访问erhereum的状态时, 最后默认的block参数决定了block的高度,该选项能够是一下的取值, defaultBlock:
curl 命令参数中 --data 默认指定数据类型为 application/x-www-form-urlencoded, 若是是其余的格式, 须要手动指定, 例如: -H "application/json" , 最后面必须跟 URL/IP 和 端口, 例如 : curl e.x. 127.0.0.1:8545