getBlock
Returns information about a block at a block number, hash or tag
Loading...
Returns information about a block at a block number, hash or tag
Import the public actions package so you can call this action.
import "github.com/ChefBingbong/viem-go/actions/public"A minimal example showing how to construct a public client and fetch block data.
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() }()
// Get latest blockblock, err := public.GetBlock(ctx, publicClient, public.GetBlockParameters{})if err != nil { log.Fatal(err)}log.Printf("Block number: %d", block.Number)*types.Block
Information about the block.
Configuration options accepted by this action.
*common.HashInformation at a given block hash.
import ( "github.com/ethereum/go-ethereum/common" "github.com/ChefBingbong/viem-go/actions/public")
blockHash := common.HexToHash("0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d")block, err := public.GetBlock(ctx, publicClient, public.GetBlockParameters{ BlockHash: &blockHash,})*uint64Information at a given block number.
import "github.com/ChefBingbong/viem-go/actions/public"
blockNum := uint64(42069)block, err := public.GetBlock(ctx, publicClient, public.GetBlockParameters{ BlockNumber: &blockNum,})BlockTag"latest"Information at a given block tag.
import "github.com/ChefBingbong/viem-go/actions/public"
block, err := public.GetBlock(ctx, publicClient, public.GetBlockParameters{ BlockTag: public.BlockTagSafe,})boolfalseWhether or not to include transactions (as a structured array of Transaction objects).
import "github.com/ChefBingbong/viem-go/actions/public"
block, err := public.GetBlock(ctx, publicClient, public.GetBlockParameters{ IncludeTransactions: true,})Underlying JSON-RPC methods used by this action.
eth_getBlockByNumber for blockNumber & blockTag.eth_getBlockByHash for blockHash.