viem-goviem-go

getFilterLogs

Returns a list of event logs since the filter was created

Returns a list of event logs since the filter was created.

Note: getFilterLogs is only compatible with event filters.

Import

Import the public actions package so you can call this action.

import "github.com/ChefBingbong/viem-go/actions/public"

Usage

With a basic event filter, you can retrieve all logs since the filter was created:

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.GetFilterLogs(ctx, publicClient, public.GetFilterLogsParameters{
Filter: filter.ID,
})
if err != nil {
log.Fatal(err)
}
log.Printf("Found %d logs", len(logs))

With a contract event filter (includes decoded args), you also get decoded arguments for each log:

contractAddr := common.HexToAddress("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")
erc20ABI, _ := abi.ParseABI(`[{"anonymous":false,"inputs":[...],"name":"Transfer",...}]`)
filter, _ := public.CreateContractEventFilter(ctx, publicClient, public.CreateContractEventFilterParameters{
Address: contractAddr,
ABI: erc20ABI,
EventName: "Transfer",
})
logs, err := public.GetFilterLogs(ctx, publicClient, public.GetFilterLogsParameters{
Filter: filter, - Pass the full filter object for ABI decoding
})
if err != nil {
log.Fatal(err)
}
// logs will have DecodedArgs populated

Returns

[]ContractEventLog

A list of event logs, each containing:

  • Log formatters.Log - The raw log data
  • EventName string - The decoded event name (if ABI was provided)
  • DecodedArgs map[string]any - The decoded event arguments (if ABI was provided)

Parameters

Configuration options accepted by this action.

Filter

  • Type: any (accepts FilterID, *CreateEventFilterReturnType, or *CreateContractEventFilterReturnType)
  • Required

The filter to get logs for. Can be a basic event filter or a contract event filter with ABI.

filter, err := public.CreateEventFilter(ctx, publicClient, public.CreateEventFilterParameters{
Address: contractAddr,
})
if err != nil {
log.Fatal(err)
}
logs, err := public.GetFilterLogs(ctx, publicClient, public.GetFilterLogsParameters{
Filter: filter.ID,
})

JSON-RPC Method

Underlying JSON-RPC method used by this action.

eth_getFilterLogs