JsonRPC
Ethereum uses JsonRPC as the main interface to interact with the client and the network.
Overview
package main
import ( "github.com/umbracle/ethgo/jsonrpc")
func main() { client, err := jsonrpc.NewClient("https://mainnet.infura.io") if err != nil { panic(err) }}
Ethgo supports different transport protocols besides http depending on the endpoint:
Use the endpoint with wss:// prefix to connect with websockets:
client, err := jsonrpc.NewClient("wss://mainnet.infura.io")
or the endpoint with ipc:// prefix to use ipc:
client, err := jsonrpc.NewClient("ipc://path/geth.ipc")
Endpoints
Once the JsonRPC client has been created, the endpoints are available on different namespaces following the spec:
eth := client.Eth()
The available namespaces are:
Block tag
Some endpoints of the eth namespace can be queried at a specific block. There exists three ways to specify this block:
-
numberortag(BlockNumber): integer block number or the taglatest,pendingorearliest. -
hash(Hash): hash of the block.