1 Ethereum RPC APIs
1) Standard APIs
2) Geth Specific APIs
2 Ethereum RPC
1) HTTP-RPC:手动启动
--rpc --rpcaddr --rpcport --rpcapi --rpccorsdomain
2) WS-RPC:手动启动
--ws --wsaddr --wsport --wsapi --wsorigins
3) IPC-RPC:自动启动
--ipcdisable --ipcapi --ipcpath
注:出于安全考虑,接口默认开放API子集,通过相应参数可以进行配置。
3 HTTP-RPC 调用实例
# 运行以太坊私有链节点并配置参数
docker run -it -d --name eth-noderpc -p 30303:30303 -p 8545:8545 --net eth-network --ip 172.25.0.10 ethereum:3.0 --rpc --rpcaddr "0.0.0.0" --rpcapi "admin,debug,eth, miner,net,personal,shh,txpool,web3" --nodiscover --networkid 15
注:
--rpc 启用HTTP-RPC服务
--rpcaddr 服务监听接口,默认“localhost”
--rpcapi 配置可使用的api接口,默认“eth, net, web3”
# 调用RPC接口
# 查看账户信息
curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0", "method":"eth_accounts","params":[],"id":67}' 172.25.0.10:8545# 查看账户余额
curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0", "method":"eth_getBalance","params":["0xde1e758511a7c67e7db93d1c23c1060a21db4615","latest"],"id":67}' 172.25.0.10:8545# 查看区块高度
curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0", "method":"eth_blockNumber","params":[],"id":67}' 172.25.0.10:8545# 解锁账户
curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0", "method":"personal_unlockAccount","params":["0xde1e758511a7c67e7db93d1c23c1060a21db4615","password",300],"id":67}' 172.25.0.10:8545# 发送交易
curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params": [{ "from": "0xde1e758511a7c67e7db93d1c23c1060a21db4615", "to": "0xd64a66c28a6ae5150af5e7c34696502793b91ae7", "value": "0x1" }], "id":67}' 172.25.0.10:8545# 查看交易状态
curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0", "method":"miner_start","params":[],"id":67}' 172.25.0.10:8545# 开启挖矿
curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0", "method":"miner_start","params":[],"id":67}' 172.25.0.10:8545# 结束挖矿
curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0", "method":"miner_stop","params":[],"id":67}' 172.25.0.10:8545
4 参考
https://github.com/ethereum/go-ethereum
https://github.com/ethereum/wiki/wiki/JSON-RPC
https://github.com/ethereum/go-ethereum/wiki/Management-APIs