getLogs
Returns a list of event logs matching the provided parameters
Returns a list of event logs matching the provided parameters
Import the public actions package so you can call this action.
import "github.com/ChefBingbong/viem-go/actions/public"An example showing how to construct a public client and fetch logs that match a simple filter.
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")fromBlock := uint64(16330000)toBlock := uint64(16330050)
logs, err := public.GetLogs(ctx, publicClient, public.GetLogsParameters{ Address: contractAddr, FromBlock: &fromBlock, ToBlock: &toBlock,})if err != nil { log.Fatal(err)}log.Printf("Found %d logs", len(logs))[]formatters.Log
A list of event logs matching the filter criteria.
Configuration options accepted by this action.
any (accepts common.Address, *common.Address, []common.Address, string, or []string)The contract address(es) to filter logs from. Can be a single address or a slice of addresses.
import ( "github.com/ethereum/go-ethereum/common" "github.com/ChefBingbong/viem-go/actions/public")
contractAddr := common.HexToAddress("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")logs, err := public.GetLogs(ctx, publicClient, public.GetLogsParameters{ Address: contractAddr,})[]anyThe indexed event topics to filter. Each topic can be a single value or an array of values (OR condition).
transferTopic := common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")logs, err := public.GetLogs(ctx, publicClient, public.GetLogsParameters{ Address: contractAddr, Topics: []any{transferTopic},})*uint64The block number to start filtering from. Mutually exclusive with FromBlockTag.
fromBlock := uint64(16330000)logs, err := public.GetLogs(ctx, publicClient, public.GetLogsParameters{ Address: contractAddr, FromBlock: &fromBlock,})BlockTagThe block tag to start filtering from. Mutually exclusive with FromBlock.
logs, err := public.GetLogs(ctx, publicClient, public.GetLogsParameters{ Address: contractAddr, FromBlockTag: public.BlockTagSafe,})*uint64The block number to stop filtering at. Mutually exclusive with ToBlockTag.
toBlock := uint64(16330050)logs, err := public.GetLogs(ctx, publicClient, public.GetLogsParameters{ Address: contractAddr, ToBlock: &toBlock,})BlockTagThe block tag to stop filtering at. Mutually exclusive with ToBlock.
logs, err := public.GetLogs(ctx, publicClient, public.GetLogsParameters{ Address: contractAddr, ToBlockTag: public.BlockTagLatest,})*common.HashFilters logs from a specific block by hash. Mutually exclusive with FromBlock/ToBlock.
blockHash := common.HexToHash("0x...")logs, err := public.GetLogs(ctx, publicClient, public.GetLogsParameters{ BlockHash: &blockHash,})Underlying JSON-RPC method used by this action.