geth console命令


一,建立开发环境:
geth --rpc --rpcport 9999 --dev --mine --minerthreads 1  console 2>>geth.log 
 
二、测试:
1.net_listening   查看geth rpc端口是否开放
> curl -H "Content-Type: application/json"  --data '{"jsonrpc":"2.0","method":"net_listening", "params":[],"id":1}'  39.107.236.48:8545

#{"jsonrpc":"2.0","id":1,"result":true}

  

 
#{"jsonrpc":"2.0","id":1,"result":true}   
 
2.web3_clientVersion   查看geth版本
> curl -H "Content-Type: application/json"  --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}'  39.107.236.48:8545

# {"jsonrpc":"2.0","id":67,"result":"Geth/g1/v1.8.1-stable-1e67410e/linux-amd64/go1.9.4”}   查看geth版本

3.web3_sha3   把数据转换成SHA3格式

 
> curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"web3_sha3","params":["0x68656c6c6f20776f726c64"],"id":64}' 39.107.236.48:8545

#{"jsonrpc":"2.0","id":64,"result":"0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"}

 

4.net_version   返回当前网络ID

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"net_version","params":["0x68656c6c6f20776f726c64"],"id":64}' 39.107.236.48:8545

#{"jsonrpc":"2.0","id":64,"result":"100"}

  • "1": Ethereum Mainnet
  • "2": Morden Testnet (deprecated)
  • "3": Ropsten Testnet
  • "4": Rinkeby Testnet
  • "42": Kovan Testnet
  • "100":等其它数字为个人自定义私有网络
 

 

5.net_peerCount   返回当前节点的peers数量

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"net_peerCount","params":[],"id":64}' 39.107.236.48:8545

#{"jsonrpc":"2.0","id":64,"result":"0x2"} //2

 

6.eth_protocolVersion    返回当前ethereum 协议版本

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_protocolVersion","params":[],"id":64}' 39.107.236.48:8545

#{"jsonrpc":"2.0","id":64,"result":"0x3f"} //63

 

7.eth_syncing   返回包含有关同步状态的对象或false.

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":64}' 39.107.236.48:8545
#{"jsonrpc":"2.0","id":64,"result":false}

// Result 正在同步的情况下返回
{ "id":1, "jsonrpc": "2.0", "result": { startingBlock: '0x384', currentBlock: '0x386', highestBlock: '0x454' } } // Or when not syncing 同步完成或没有同步返回 { "id":1, "jsonrpc": "2.0", "result": false }

8.eth_coinbase 获取第一个账号的地址

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_coinbase","params":[],"id":64}' 39.107.236.48:8545

#{"jsonrpc":"2.0","id":64,"result":"0x2216bbda225f67fed72b416329a29664535104d9"}

 

9.eth_mining 获取挖矿状态

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_mining","params":[],"id":64}' 39.107.236.48:8545

#{"jsonrpc":"2.0","id":64,"result":false}

 

10.eth_hashrate  获取当前节点的挖矿算力

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_hashrate","params":[],"id":64}' 39.107.236.48:8545

#{"jsonrpc":"2.0","id":64,"result":"0x1084"}

 

11.eth_gasPrice   返回每wei的gas价格

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":64}' 39.107.236.48:8545

#{"jsonrpc":"2.0","id":64,"result":"0x430e23400"} //18000000000

 

12.eth_accounts  返回客户端地址列表

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":64}' 39.107.236.48:8545

#{"jsonrpc":"2.0","id":64,"result":["0x2216bbda225f67fed72b416329a29664535104d9","0x9ee25a5378f29633087936c507e8226ed5ea27fd"]}

 

13.eth_blockNumber   返回块数

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":64}' 39.107.236.48:8545
#{"jsonrpc":"2.0","id":64,"result":"0xb838"} //2014

 

14.eth_getBalance 获取余额

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x2216bbda225f67fed72b416329a29664535104d9","latest"],"id":64}' 39.107.236.48:8545
#{"jsonrpc":"2.0","id":64,"result":"0x52b9fa1ddb74470c8daf00"} //100010168845190000246624828

参考:https://github.com/ethereum/wiki/wiki/JSON-RPC#the-default-block-parameter

The following methods have an extra default block parameter:

 
    
   

When requests are made that act on the state of ethereum, the last default block parameter determines the height of the block.

The following options are possible for the defaultBlock parameter:

 
   
  • HEX String - an integer block number
  • String "earliest" for the earliest/genesis block
  • String "latest" - for the latest mined block
  • String "pending" - for the pending state/transactions
 

 

15.eth_getStorageAt   返回给定地址的存储位置的值

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getStorageAt","params":["0x2216bbda225f67fed72b416329a29664535104d9","0x0","latest"],"id":64}' 39.107.236.48:8545

 

16.eth_getTransactionCount   返回从地址发送的交易数量

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["0x2216bbda225f67fed72b416329a29664535104d9","latest"],"id":1}' 39.107.236.48:8545
 
  

 

17.eth_getBlockTransactionCountByHash   返回交易所在的块号

 

 

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM