[**] geth - rpc的用法

访问量: 123

https://github.com/ethereum/wiki/wiki/JSON-RPC

和 : https://github.com/ethereum/go-ethereum/wiki/Management-APIs

需要说明的是, 在 RPC 文档中, 没有给出 personal的例子. 实际上,只要在 console里可以用的  (personal 的 someMethod) , 在 RPC 中就可以调用.  ... "method": "personal_someMethod"

查看当前节点下的 所有 keystore(账户)

$ curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}' localhost:8545
{"jsonrpc":"2.0","id":1,"result":["0x5b51ca3701af0807bf081c1b04878ac47ed35331","0x7056cbcaaedb2e89b37992806aa76e3d3ba1267f","0x41fdcf7c022976527e0a420c21ca5134d2b86b98","0x5d2055ab052fadf2ef11e4ec0cc4d2e76b3cc3fa","0xdd1d2e109b2c09cd75ce234890841d59f57c7acd"]}

查看某个账户的余额:   (通常用来判断 当前的Geth节点是否正确的同步下来了) 

$ curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x8f5ae589fd2467396c8b25559637dbf5c4401464", "latest"],"id":1}' 127.0.0.1:8545
{"jsonrpc":"2.0","id":1,"result":"0x10d056640e578b0"}

查看当前的gas价格: 

$ curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":1}' localhost:8545
{"jsonrpc":"2.0","id":1,"result":"0x1dcd65000"}

查看当前的coinbase : 

$ curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_coinbase","params":[],"id":1}' localhost:8545
{"jsonrpc":"2.0","id":1,"result":"0x5b51ca3701af0807bf081c1b04878ac47ed35331"}

unlock某个账户( 这个没有出现在 RPC 文档中, 我们可以在 console文档中看到 )

可以用来验证某个ETH账户的用户名和密码是否匹配.  在转款前,都是要求是 unlock状态

# curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"personal_unlockAccount","params":["0xdd1d2e109bce234890841d59f57c7acd", "fCX&)g%BN5ko7pdFSVlNihir4Enu&$HfLdF", 300],"id":3}' 127.0.0.1:8545
{"jsonrpc":"2.0","id":3,"result":true}

订阅/RSS Feed

Subscribe

分类/category