add basic rpc client calling admin_peers

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-06-16 11:23:24 -04:00 committed by Jakub
parent fb913dbcf6
commit 3565768230
1 changed files with 29 additions and 0 deletions

29
main.go Normal file
View File

@ -0,0 +1,29 @@
package main
import (
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/rpc"
"log"
)
type rcpResp map[string]interface{}
const serverAddr = "127.0.0.1"
const serverPort = 8545
func main() {
addr := fmt.Sprintf("http://%s:%d", serverAddr, serverPort)
c, err := rpc.DialHTTP(addr)
if err != nil {
log.Fatal("Failed to connec to RPC:", err)
}
fmt.Println("Connected: ", addr)
var rval interface{}
err = c.Call(&rval, "admin_peers")
if err != nil {
log.Fatal("Failed to make RPC call:", err)
}
pretty, err := json.MarshalIndent(rval, "", " ")
fmt.Println("Response: ", string(pretty))
}