以太坊—JSON RPC API

Geth 使用JSON數據格式, JSON-RPC協議做爲客戶端和網絡進行交互的方法。 Geth 1.4 的 pub/sub 是實驗性質的, 一樣, Partity 1.6 也是。node

JavaScript API

使用web3.js和etherenum節點交互時, 遵循一致的RPC協議.web

 

JSON-RPC Endpoint

默認的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

 

十六進制值編碼 HEX value encoding

目前, 有2中主要的數據烈性用於JSON, unformatted byte arrays 和 quantities, 他們都是經過hex編碼傳遞的。

 

默認block 參數

下面的方法有一個額外的默認的block參數:

  • eth_getBalance
  • eth_getCode
  • eth_getTransactionCount
  • eth_getStorageAt
  • eth_call

當請求訪問erhereum的狀態時, 最後默認的block參數決定了block的高度,該選項能夠是一下的取值, defaultBlock:

  • HEX String 一個integer block 值
  • String "earliest" 用於earliest/genesis block
  • String "latest" 用於最近挖出的block
  • String "pending" 用於pending 的 state/transactions

 

 

Curl 例子解釋

curl 命令參數中 --data 默認指定數據類型爲 application/x-www-form-urlencoded, 若是是其餘的格式, 須要手動指定, 例如: -H "application/json" , 最後面必須跟 URL/IP 和 端口, 例如 : curl e.x. 127.0.0.1:8545

 

JSON-RPC 方法

  • web3_clientVersion
  • web3_sha3

 

  • net_version
  • net_peeCount
  • net_listening

 

  • eth_protocolVersion
  • eth_syncing
  • eth_coinbase
  • eth_mining
  • eth_hashrate
  • eth_gasPrice
  • eth_accounts
  • eth_blockNumber
  • eth_getBalance
  • eth_getStorageAt
  • eth_getTransactionCount
  • eth_getBlockTransactionCountByHash
  • eth_getBlockTransactionCountByNumber
  • eth_getUncleCountByBlockHash
  • eth_getUncleCountByBlockNumber
  • eth_getCode
  • eth_sign
  • eth_sendTransaction
  • eth_sendRawTransaction
  • eth_call
  • eth_estimateGas
  • eth_getBlockByHash
  • eth_getBlockByNumber
  • eth_getTransactionByHash
  • eth_getTransactionByBlockHashAndIndex
  • eth_getTransactionByBlockNumberAndIndex
  • eth_getTransactionReceipt
  • eth_getUncleByBlockHashAndIndex
  • eth_getUnclueByBlockNumberAndIndex
  • eth_getCompilers
  • eth_compileSolidity
  • eth_compileSerpent
  • eth_newFilter
  • eth_newBlockFilter
  • eth_newPendingTransactionFilter
  • eth_uninstallFilter
  • eth_getFilterChanges
  • eth_getFilterLogs
  • eth_getLogs
  • eth_getWork
  • eth_submitWork
  • eth_submitHashrate

 

  • db_putString
  • db_getString
  • db_putHex
  • db_getHex

 

  • shh_post
  • shh_version
  • shh_newIdentity
  • shh_hasIdentity
  • shh_newGroup
  • shh_addToGroup
  • shh_newFilter
  • shh_uninstallFilter
  • shh_getFilterChanges
  • shh_getMessages
相關文章
相關標籤/搜索