无论web3.js
还是web3j
,都是对以太坊JSON RPC API
开发接口的封装。
以太坊JSON RPC API手册
由汇智网组织翻译,强力推荐开发者收藏备用。
JSON RPC是一种无状态轻量级远程过程调用(RPC)协议。以太坊JSON RPC API规范定义了数据结构
及相应的处理规则。规范本身是传输无关的,可以用于进程内通信、socket套接字、HTTP 或各种消
息通信环境。规范使用JSON(RFC 4627)数据格式。
不同的客户端默认JSON-RPC端结点如下:
- C++ - http://localhost:8545
- Go - http://localhost:8545
- Py - http://localhost:4000
- Parity- http://localhost:8545
- Ganache-cli - http://localhost:8545
使用curl
来测试JSON RPC API非常简单。例如,查询节点持有的账户地址清单:
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}'
响应结果如下:
{
"id":1,
"jsonrpc": "2.0",
"result": ["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]
}