Skip to content

Instantly share code, notes, and snippets.

@yusuketanabe
Created October 23, 2021 06:43
Show Gist options
  • Save yusuketanabe/98b86848455e961d3fc3ad46872e48c9 to your computer and use it in GitHub Desktop.
Save yusuketanabe/98b86848455e961d3fc3ad46872e48c9 to your computer and use it in GitHub Desktop.
Ethereum Client Sample
package main
import (
"context"
"fmt"
"log"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)
func main() {
conn, err := ethclient.Dial("https://mainnet.infura.io/v3/b710e5c3e7154eb79ac647cbcdc20308")
if err != nil {
log.Fatal("Whoops something went wrong!", err)
}
ctx := context.Background()
tx, pending, _ := conn.TransactionByHash(ctx, common.HexToHash("0x7a51b3b6b493dffc0a11a98871a730c1634b3ea7d685d1ce5f1f4a6346cf66be"))
if !pending {
fmt.Println(tx)
}
}

About this code

これはGolangを使ってEthereumのトランザクションに接続して、その情報を取得するものである。 Infura.ioを使ってEthereumのmainnetにアクセスしている。もしdAppsを作ろうとしてテストしたい場合などは、開発段階ではtestnetにアクセスするように。mainneteは本番環境です。 ちなみにEthereumScanからトランザクションハッシュを持ってきた。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment