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