1

I'm aware that I can do this using CURL like so:

curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' https://the-node-ip-address:8545

Which return the following output:

{"jsonrpc":"2.0","id":67,"result":"Geth/v1.8.22-omnibus-260f7fbd/linux-amd64/go1.11.1"}

OR

{"jsonrpc":"2.0","result":"Parity-Ethereum//v2.2.11-stable-8e31051-20190220/x86_64-linux-gnu/rustc1.32.0","id":67}

Is there a way to do this using any package from go-ethereum project? All I have with me is a node RPC URL i.e. http://123.45.678.912:8545 and I want to check if it's a Geth node or Parity node using Golang without needing to convert the CURL above to Go code.

I'm looking for something like this:

import "github.com/ethereum/go-ethereum/ethclient"
...
client := ethclient.Dial("http://123.45.678.912:8545")
clientType := client.Xxx() // <-- I need this method and it should return "Geth" or "Parity"

What is the method for Xxx() above?

1

The ethclient package doesn't provide a method for that but you can use the rpc package to do what you need. Here's a working example:

package main

import (
    "fmt"

    "github.com/ethereum/go-ethereum/rpc"
)

func main() {
    client, err := rpc.DialHTTP("https://mainnet.infura.io")
    if err != nil {
        panic(err)
    }

    var res string
    req := struct {
        To   string `json:"to"`
        Data string `json:"data"`
    }{}

    if err := client.Call(&res, "web3_clientVersion", req, "latest"); err != nil {
        panic(err)
    }

    fmt.Println(res) // Geth/v1.8.22-omnibus-260f7fbd/linux-amd64/go1.11.1
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.