viem-goviem-go

getTransaction

Returns information about a transaction given a hash or block identifier

Import

Import the public actions package so you can call this action.

import "github.com/ChefBingbong/viem-go/actions/public"

Usage

An example showing how to construct a public client and fetch a transaction.

import (
"context"
"log"
"github.com/ethereum/go-ethereum/common"
"github.com/ChefBingbong/viem-go/actions/public"
"github.com/ChefBingbong/viem-go/client"
"github.com/ChefBingbong/viem-go/client/transport"
"github.com/ChefBingbong/viem-go/chain/definitions"
)
ctx := context.Background()
publicClient, err := client.CreatePublicClient(client.PublicClientConfig{
Chain: definitions.Mainnet,
Transport: transport.HTTP("https://eth.llamarpc.com"),
})
if err != nil {
log.Fatal(err)
}
defer func() { _ = publicClient.Close() }()
txHash := common.HexToHash("0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d")
tx, err := public.GetTransaction(ctx, publicClient, public.GetTransactionParameters{
Hash: &txHash,
})
if err != nil {
log.Fatal(err)
}
log.Printf("Transaction from: %s", tx.From.Hex())

Returns

*TransactionResponse

The transaction information.

Parameters

Configuration options accepted by this action.

Hash

  • Type: *common.Hash
  • Optional

Get information about a transaction given a transaction hash.

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ChefBingbong/viem-go/actions/public"
)
txHash := common.HexToHash("0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d")
tx, err := public.GetTransaction(ctx, publicClient, public.GetTransactionParameters{
Hash: &txHash,
})

BlockHash

  • Type: *common.Hash
  • Optional

Get information about a transaction given a block hash (must be used with Index).

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ChefBingbong/viem-go/actions/public"
)
blockHash := common.HexToHash("0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d")
index := 0
tx, err := public.GetTransaction(ctx, publicClient, public.GetTransactionParameters{
BlockHash: &blockHash,
Index: &index,
})

BlockNumber

  • Type: *uint64
  • Optional

Get information about a transaction given a block number (must be used with Index).

import "github.com/ChefBingbong/viem-go/actions/public"
blockNum := uint64(69420)
index := 0
tx, err := public.GetTransaction(ctx, publicClient, public.GetTransactionParameters{
BlockNumber: &blockNum,
Index: &index,
})

BlockTag

  • Type: BlockTag
  • Optional

Get information about a transaction given a block tag (must be used with Index).

import "github.com/ChefBingbong/viem-go/actions/public"
index := 0
tx, err := public.GetTransaction(ctx, publicClient, public.GetTransactionParameters{
BlockTag: public.BlockTagSafe,
Index: &index,
})

Index

  • Type: *int
  • Optional

An index to be used with a block identifier (number, hash or tag).

import "github.com/ChefBingbong/viem-go/actions/public"
index := 0
tx, err := public.GetTransaction(ctx, publicClient, public.GetTransactionParameters{
BlockTag: public.BlockTagSafe,
Index: &index,
})

JSON-RPC Method

Underlying JSON-RPC methods used by this action.