createBlockFilter
Creates a filter to listen for new blocks
Import
Import the public actions package so you can call this action.
import "github.com/ChefBingbong/viem-go/actions/public"Usage
A minimal example showing how to construct a public client and create a block filter.
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.CreateBlockFilter(ctx, publicClient)if err != nil { log.Fatal(err)}
// Use filter.ID with GetFilterChanges to get new block hasheschanges, err := public.GetFilterChanges(ctx, publicClient, public.GetFilterChangesParameters{ FilterID: filter.ID,})Returns
*CreateBlockFilterReturnType
A filter object containing:
ID FilterID- The filter identifierType string- Always"block"for block filters
Parameters
This action takes no parameters.