ethereum-rpc-demo
所属分类:以太坊
开发工具:GO
文件大小:2KB
下载次数:0
上传日期:2018-03-29 05:23:02
上 传 者:
sh-1993
说明: 演示如何基于以太坊代码库对RPC服务器进行编程
(a demo for how to program a RPC server based on ethereum code base)
文件列表:
LICENSE (1057, 2018-03-29)
main.go (1583, 2018-03-29)
ethereum-rpc-demo demonstrate how to write your own RPC server base on the rpc framework provided by go-ethereum
# Dependency
install: `go get github.com/ethereum/go-ethereum`
# Run
run: `go run main.go`
if server start successfully, you will get:
```
RPC HTTP endpoint opened url http://127.0.0.1:9010 cors vhosts
```
our service is registered in rpc server under the namespace `kfchen`
# Test
use curl to post data to RPC server
### kfchen_echo
```
curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"kfchen_echo","params":["ping"],"id":67}' http://127.0.0.1:9010
```
Result:
```
{"jsonrpc":"2.0","id":67,"result":"ping from echo"}
```
### kfchen_getPerson
```
curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"kfchen_getPerson","params":[{"name":"robert"}],"id":67}' http://127.0.0.1:9010
```
Result:
```
{"jsonrpc":"2.0","id":67,"result":{"desc":"good man","name":"kfchen"}}
```
### rpc_modules
Namespace `rpc` is registered by ethereum rpc server itself when it started. We can use it to retrieve some meta info about rpc server itself.
```
curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"rpc_modules","params":[],"id":67}' http://127.0.0.1:9010
```
Result:
```
{"jsonrpc":"2.0","id":67,"result":{"kfchen":"1.0","rpc":"1.0"}}
```
We can see `kfchen namespace` and `rpc namespace`
# See Also
[Ethereum JSON-RPC Wiki](https://github.com/ethereum/wiki/wiki/JSON-RPC)
近期下载者:
相关文件:
收藏者: