viem-goviem-go

createPendingTransactionFilter

Creates a filter to listen for new pending transactions

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 create a pending transaction filter and use it to fetch new transactions.

import (
"context"
"log"
"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() }()
filter, err := public.CreatePendingTransactionFilter(ctx, publicClient)
if err != nil {
log.Fatal(err)
}
// Use filter.ID with GetFilterChanges to get new pending transaction hashes
changes, err := public.GetFilterChangesTransactions(ctx, publicClient, filter.ID)

Returns

*CreatePendingTransactionFilterReturnType

A filter object containing:

  • ID FilterID - The filter identifier
  • Type string - Always "transaction" for pending transaction filters

Parameters

This action takes no parameters.

JSON-RPC Method

Underlying JSON-RPC method used by this action.

eth_newPendingTransactionFilter