getFilterChanges
Returns a list of logs or hashes based on a filter since the last time it was called
Returns a list of logs or hashes based on a filter since the last time it was called
Returns a list of logs or hashes based on a filter since the last time it was called.
A filter can be created from:
Import the public actions package so you can call this action.
import "github.com/ChefBingbong/viem-go/actions/public"Fetch filter changes for an event filter and inspect the new logs since the last poll.
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() }()
contractAddr := common.HexToAddress("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")filter, _ := public.CreateEventFilter(ctx, publicClient, public.CreateEventFilterParameters{ Address: contractAddr,})
logs, err := public.GetFilterChangesLogs(ctx, publicClient, filter.ID)if err != nil { log.Fatal(err)}log.Printf("Found %d new logs", len(logs))Fetch filter changes for a block filter and inspect newly seen block hashes.
filter, _ := public.CreateBlockFilter(ctx, publicClient)
blockHashes, err := public.GetFilterChangesBlocks(ctx, publicClient, filter.ID)if err != nil { log.Fatal(err)}log.Printf("Found %d new blocks", len(blockHashes))Fetch filter changes for a pending transaction filter and inspect newly seen transaction hashes.
filter, _ := public.CreatePendingTransactionFilter(ctx, publicClient)
txHashes, err := public.GetFilterChangesTransactions(ctx, publicClient, filter.ID)if err != nil { log.Fatal(err)}log.Printf("Found %d new pending transactions", len(txHashes))The return type depends on the filter type:
[]formatters.Log - For event filters (via GetFilterChangesLogs)[]common.Hash - For block filters (via GetFilterChangesBlocks)[]common.Hash - For pending transaction filters (via GetFilterChangesTransactions)Configuration options accepted by this action.
FilterIDThe filter identifier returned by CreateEventFilter, CreateBlockFilter, or CreatePendingTransactionFilter.
filter, err := public.CreateEventFilter(ctx, publicClient, public.CreateEventFilterParameters{ Address: contractAddr,})if err != nil { log.Fatal(err)}
logs, err := public.GetFilterChangesLogs(ctx, publicClient, filter.ID)Underlying JSON-RPC method used by this action.