# geth相关rpc调用例子

By [Untitled](https://paragraph.com/@0x99ca2f74d795e73bfd041f4c674e770c439ed360) · 2021-10-11

---

查看地址：[https://github.com/ethereum/wiki/wiki/JSON-RPC#curl-examples-explained](https://github.com/ethereum/wiki/wiki/JSON-RPC#curl-examples-explained)

1.查看web3的版本

> curl localhost:7777 -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"web3\_clientVersion","params":\[\],"id":67}'

2.查看同步的网络net\_version

> curl localhost:7777 -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"net\_version","params":\[\],"id":67}'

"1": Ethereum Mainnet "2": Morden Testnet (deprecated) "3": Ropsten Testnet "4": Rinkeby Testnet "42": Kovan Testnet

3.是否在监听网络连接

> curl localhost:7777 -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"net\_listening","params":\[\],"id":67}'

4.返回当前连接到客户机的对等点的数量

> curl localhost:7777 -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"net\_peerCount","params":\[\],"id":74}'

5.返回当前ethereum协议版本

> curl localhost:7777 -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"eth\_protocolVersion","params":\[\],"id":67}'

6.获取当前的同步状态(返回的结果是16进制)

> curl localhost:7777 -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"eth\_syncing","params":\[\],"id":1}'

7.返回节点的主地址 client coinbase address

> curl localhost:7777 -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"eth\_coinbase","params":\[\],"id":64}'

8.节点是否在挖矿

> curl localhost:7777 -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"eth\_mining","params":\[\],"id":71}'

9.查询当前的gas price ,单位wei

> curl localhost:7777 -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"eth\_gasPrice","params":\[\],"id":73}'

10.查询该节点的账户eth\_accounts

> curl localhost:7777 -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"eth\_accounts","params":\[\],"id":1}'

11.查询最新的区块高度

> curl localhost:7777 -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"eth\_blockNumber","params":\[\],"id":1}'

12.查询账户余额

> curl localhost:7777 -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"eth\_getBalance","params":\["0xc94770007dda54cF92009BFF0dE90c06F603a09f", "latest"\],"id":1}'

13.获取某个地址的交易次数

> curl localhost:7777 -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"eth\_getTransactionCount","params":\["0xc94770007dda54cF92009BFF0dE90c06F603a09f","latest"\],"id":1}'

14.查询某一个块的hash的交易数(没测试成功)

> curl localhost:7777 -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"eth\_getBlockTransactionCountByHash","params":\["0xc94770007dda54cF92009BFF0dE90c06F603a09f"\],"id":1}'

15.查询某一个块的交易数

> curl localhost:7777 -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"eth\_getBlockTransactionCountByNumber","params":\["0x6ea7ce"\],"id":1}'

#### 碰到的异常情况说明：

1.如果提示The method net\_version does not exist/is not available 可能是对应的rpc接口没打开

---

*Originally published on [Untitled](https://paragraph.com/@0x99ca2f74d795e73bfd041f4c674e770c439ed360/geth-rpc)*
