Skip to content

Instantly share code, notes, and snippets.

@crazygit
Created April 26, 2022 09:29

Revisions

  1. crazygit revised this gist Apr 26, 2022. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion go-ethereum-get-transaction.go
    Original file line number Diff line number Diff line change
    @@ -25,6 +25,5 @@ func main() {
    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("Transaction Hash: %s\n", tx.Hash().Hex())
    fmt.Printf("isPending: %t\n", isPending)
    }
  2. crazygit created this gist Apr 26, 2022.
    30 changes: 30 additions & 0 deletions go-ethereum-get-transaction.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    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("Transaction Hash: %s\n", tx.Hash().Hex())
    fmt.Printf("isPending: %t\n", isPending)
    }