Skip to content

Instantly share code, notes, and snippets.

@crazygit
Created April 26, 2022 09:29
Show Gist options
  • Save crazygit/549fa73c4c5f04e41a8eb2a68bb1c236 to your computer and use it in GitHub Desktop.
Save crazygit/549fa73c4c5f04e41a8eb2a68bb1c236 to your computer and use it in GitHub Desktop.
Get transaction value and data
package main
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"log"
)
const ropstenHttpsEndpoint = "https://ropsten.infura.io/v3/77a8f7b1379d440b8c06e82f37d05657"
func main() {
client, err := ethclient.Dial(ropstenHttpsEndpoint)
if err != nil {
log.Fatal(err)
}
txHash := common.HexToHash("0x389cf60f4936ee1fa81f255d0a133fd84fe6e8b69fd8a376f3ee028d134b4ff3")
tx, isPending, err := client.TransactionByHash(context.Background(), txHash)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Transaction Hash: %s\n", tx.Hash().Hex())
fmt.Printf("Transaction Value: %s\n", tx.Value())
fmt.Printf("Transaction Data: %s\n", tx.Data())
fmt.Printf("isPending: %t\n", isPending)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment