getTransactionCount
Returns the number of transactions an account has sent
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 query an account's transaction count.
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() }()
count, err := public.GetTransactionCount(ctx, publicClient, public.GetTransactionCountParameters{ Address: common.HexToAddress("0xA0Cf798816D4b9b9866b5330EEa46a18382f251e"),})if err != nil { log.Fatal(err)}log.Printf("Transaction count: %d", count)Returns
uint64
The number of transactions an account has sent.
Parameters
Configuration options accepted by this action.
Address
- Type:
common.Address - Required
The address of the account.
import ( "github.com/ethereum/go-ethereum/common" "github.com/ChefBingbong/viem-go/actions/public")
count, err := public.GetTransactionCount(ctx, publicClient, public.GetTransactionCountParameters{ Address: common.HexToAddress("0xA0Cf798816D4b9b9866b5330EEa46a18382f251e"),})BlockNumber
- Type:
*uint64 - Optional
Get the count at a block number.
import "github.com/ChefBingbong/viem-go/actions/public"
blockNum := uint64(69420)count, err := public.GetTransactionCount(ctx, publicClient, public.GetTransactionCountParameters{ Address: common.HexToAddress("0xA0Cf798816D4b9b9866b5330EEa46a18382f251e"), BlockNumber: &blockNum,})BlockTag
- Type:
BlockTag - Optional
Get the count at a block tag.
import "github.com/ChefBingbong/viem-go/actions/public"
count, err := public.GetTransactionCount(ctx, publicClient, public.GetTransactionCountParameters{ Address: common.HexToAddress("0xA0Cf798816D4b9b9866b5330EEa46a18382f251e"), BlockTag: public.BlockTagSafe,})Notes
- The transaction count of an account can also be used as a nonce.
JSON-RPC Method
Underlying JSON-RPC method used by this action.