From cb3fa8a0b1c55c71de8addacb6c025f44372e03b Mon Sep 17 00:00:00 2001 From: Oskar Thoren Date: Wed, 9 Jun 2021 20:29:17 +0800 Subject: [PATCH] JSONRPC example --- nwaku/jsonrpc.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 nwaku/jsonrpc.go diff --git a/nwaku/jsonrpc.go b/nwaku/jsonrpc.go new file mode 100644 index 0000000..1981f9b --- /dev/null +++ b/nwaku/jsonrpc.go @@ -0,0 +1,31 @@ +package main + +import ( + "context" + "fmt" + "time" + "github.com/ethereum/go-ethereum/rpc" +) + +// NOTE Can be generalized with different transports (HTTP, IPC, WS etc) +// https://github.com/ethereum/go-ethereum/blob/master/rpc/client.go#L169 + +type WakuInfo struct { + ListenStr string `json:"listenStr"` +} + +func main() { + fmt.Println("JSON RPC request...") + + _, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + // Assumes node started + client, _ := rpc.Dial("http://127.0.0.1:8545") + var wakuInfo WakuInfo + // TODO id, params? + if err := client.Call(&wakuInfo, "get_waku_v2_debug_v1_info"); err != nil { + panic(err) + } + fmt.Println("WakuInfo ListenStr", wakuInfo.ListenStr) +}