Infura in Golang

Let’s use Go for Infura.

package main

import (
"fmt"
"log"

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

 func main(){
 _, err := ethclient.Dial("https://ropsten.infura.io/v3/44c8c501d2524f13a0312d42a0469990")

 if err != nil {
	log.Fatalf("Oops! There was a problem", err)
 } else {
	fmt.Println("Success! you are connected to Ropsten Network")
 }
}
3 Likes

I began to use the infura API for a startup project in 2017. At that time, the ethclient golang package had not been released by the go-ethereum team yet, so I looked around in github. In the end, I decided to develop my own package to interface the JSON RPC API and I released the “github.com/tarancss/ethcli” package.

One of the issues I encountered with other public clients, was that they would not support Basic Authentication in the RPC calls, so they would not be useful for Infura’s v3 API when you need a secret passphrase. I think this is the case for ethclient, unless I am missing something.

My ethcli package was tailored to my specific needs, however, it provides an easy to use functionality for most needs. Feel free to provide feedback and/or pull requests.

2 Likes

Thank you for sharing @santiman625