これはGolangを使ってEthereumのトランザクションに接続して、その情報を取得するものである。 Infura.ioを使ってEthereumのmainnetにアクセスしている。もしdAppsを作ろうとしてテストしたい場合などは、開発段階ではtestnetにアクセスするように。mainneteは本番環境です。 ちなみにEthereumScanからトランザクションハッシュを持ってきた。
Created
October 23, 2021 06:43
-
-
Save yusuketanabe/98b86848455e961d3fc3ad46872e48c9 to your computer and use it in GitHub Desktop.
Ethereum Client Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment