> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Get Filter Logs \[filter.getLogs]

Returns the logs matching an event filter.

Unlike `getChanges`, this action is not drained by polling. It returns all logs held by the filter.

## Usage

This example returns the logs matching an event filter.

:::code-group
```ts twoslash [example.ts]
import { Actions } from 'viem'
import { AbiEvent } from 'viem/utils'
import { client } from './viem.config'

const filter = await client.event.createFilter({
  address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
  event: AbiEvent.from(
    'event Transfer(address indexed from, address indexed to, uint256 value)',
  ),
})

const logs = await client.filter.getLogs({ filter })
// @log: [
// @log:   {
// @log:     address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
// @log:     args: { from: '0xd8da...', to: '0xa5cc...', value: 420n },
// @log:     blockHash: '0xabe6...01a4',
// @log:     blockNumber: 19760236n,
// @log:     eventName: 'Transfer',
// @log:     logIndex: 271,
// @log:     transactionHash: '0xcfa5...6e93',
// @log:     transactionIndex: 145,
// @log:   },
// @log: ]
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, http, publicActions } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  chain: mainnet,
  transport: http(),
}).extend(publicActions())
```
:::

### Standalone Action

Call `Actions.filter.getLogs` directly by passing the Client as the first argument.

:::code-group
```ts twoslash [example.ts]
import { Actions } from 'viem'
import { AbiEvent } from 'viem/utils'
import { client } from './viem.config'

const filter = await Actions.event.createFilter(client, {
  address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
  event: AbiEvent.from(
    'event Transfer(address indexed from, address indexed to, uint256 value)',
  ),
})

const logs = await Actions.filter.getLogs(client, { filter })
// @log: [
// @log:   {
// @log:     address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
// @log:     args: { from: '0xd8da...', to: '0xa5cc...', value: 420n },
// @log:     blockHash: '0xabe6...01a4',
// @log:     blockNumber: 19760236n,
// @log:     eventName: 'Transfer',
// @log:     logIndex: 271,
// @log:     transactionHash: '0xcfa5...6e93',
// @log:     transactionIndex: 145,
// @log:   },
// @log: ]
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, http } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  chain: mainnet,
  transport: http(),
})
```
:::

## Recipes

Use a Client method or pass the Client to the standalone action.

### Decoding Logs

Pass `abiEvent` on the filter to decode the returned logs.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'
import { AbiEvent } from 'viem/utils'

const client = Client.create({ chain: mainnet, transport: http() })
const filter = await Actions.event.createFilter(client, {
  event: AbiEvent.from( // [!code focus]
    'event Transfer(address indexed from, address indexed to, uint256 value)', // [!code focus]
  ), // [!code focus]
})

const logs = await Actions.filter.getLogs(client, { filter })
//    ^?
```

### Filtering by Indexed Arguments

Pass `args` on the filter to filter decoded logs by indexed arguments.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'
import { AbiEvent } from 'viem/utils'

const client = Client.create({ chain: mainnet, transport: http() })
const filter = await Actions.event.createFilter(client, {
  event: AbiEvent.from(
    'event Transfer(address indexed from, address indexed to, uint256 value)',
  ),
  args: { // [!code focus]
    from: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045', // [!code focus]
  }, // [!code focus]
})

const logs = await Actions.filter.getLogs(client, { filter })
```

## Return Value

`readonly Log[]`

The logs held by the event filter, decoded by `filter.abiEvent` when provided.

## Parameters

### filter

* **Type:** `Actions.filter.Filter<'event'>`

The event filter to query. Its `request` function must use the transport that created the filter ID.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'
import { AbiEvent } from 'viem/utils'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const filter = await Actions.event.createFilter(client, { // [!code focus]
  event: AbiEvent.from( // [!code focus]
    'event Transfer(address indexed from, address indexed to, uint256 value)', // [!code focus]
  ), // [!code focus]
}) // [!code focus]

const logs = await Actions.filter.getLogs(client, { filter })
```
