> **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.

# Watch Token Creation \[token.watchCreate]

Watches TIP-20 `TokenCreated` events from the token factory.

## Usage

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

const watcher = client.token.watchCreate({})

watcher.onLogs((logs) => {
  for (const log of logs) console.log(log.args)
  // @log: {
  // @log:   token: '0x20c0000000000000000000000000000000000042',
  // @log:   name: 'My Token',
  // @log:   symbol: 'MYT',
  // @log:   currency: 'USD',
  // @log:   quoteToken: '0x20C0000000000000000000000000000000000000',
  // @log:   admin: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  // @log:   salt: '0x9d3a4e2f1b8c65d0a7e4f2c9b1d8360e5a2c7f41d9b06e8352c1a4f7e0b6d914'
  // @log: }
})

// Later, tear down the watcher.
watcher.off()
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
// [!include ~/snippets/tempo/viem.config.ts:setup]
```
:::

Also callable standalone: `Actions.token.watchCreate(client, options)`, with `Actions` imported from `'viem/tempo'`.

## Recipes

### Screen New Tokens Quoted in Your Stablecoin

Watch factory creations and keep only tokens whose `quoteToken` matches your stablecoin, comparing addresses with [`Address.isEqual`](/docs/utilities/address), for example to seed a listing pipeline.

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

const pathUsd = '0x20c0000000000000000000000000000000000000'

const watcher = client.token.watchCreate({})

watcher.onLogs((logs) => {
  for (const log of logs) {
    if (!Address.isEqual(log.args.quoteToken, pathUsd)) continue // [!code focus]
    console.log('Listing candidate:', log.args.token, log.args.symbol) // [!code focus]
    // @log: Listing candidate: 0x20c0000000000000000000000000000000000042 MYT
  }
})
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
// [!include ~/snippets/tempo/viem.config.ts:setup]
```
:::

### Keep a Token Registry Current After Restarts

Pass `fromBlock` when your indexer restarts, so tokens created while it was offline are replayed into the registry before live events.

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

// Last block the registry indexed, loaded from its store.
const checkpoint = 1_204_320n

const watcher = client.token.watchCreate({
  fromBlock: checkpoint + 1n, // [!code focus]
})

watcher.onLogs((logs) => {
  for (const log of logs) {
    // Upsert into the registry keyed by token address.
    console.log(log.args.token, log.args.name, log.args.symbol, log.args.admin)
  }
})
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
// [!include ~/snippets/tempo/viem.config.ts:setup]
```
:::

## Return Value

Returns a watcher handle. Watching starts when the first listener (or async iterator) attaches, and stops when `off` is called.

```ts
type ReturnType = {
  /** Registers a log listener. Starts the watcher on first registration. Returns an unregister function. */
  onLogs: (fn: (logs: readonly Log[]) => void) => () => void
  /** Registers an error listener. Returns an unregister function. */
  onError: (fn: (error: Error) => void) => () => void
  /** Tears down the watcher: removes listeners, ends iterators, stops the poll or subscription. */
  off: () => void
  /** Async-iterates emitted log batches (latest-only stream). */
  [Symbol.asyncIterator]: () => AsyncIterableIterator<{ logs: readonly Log[] }>
}
```

Each log is decoded, with the event arguments on `args`:

```ts
type Log = {
  /** Decoded `TokenCreated` event arguments. */
  args: {
    /** Address of the created token. */
    token: Address
    /** Name of the token. */
    name: string
    /** Symbol of the token. */
    symbol: string
    /** Currency of the token. */
    currency: string
    /** Quote token address. */
    quoteToken: Address
    /** Admin address. */
    admin: Address
    /** Salt used to derive the token address. */
    salt: Hex
  }
  /** Name of the emitted event. */
  eventName: 'TokenCreated'
  // ...standard log fields (address, blockHash, blockNumber, logIndex, transactionHash, ...)
}
```

## Parameters

### args

* **Type:** `object`

```ts
type Args = {
  /** Filter by created token address. */
  token?: Address | Address[] | null
}
```

Indexed argument values to filter logs by.

### batch

* **Type:** `boolean`
* **Default:** `true`

Whether to batch the logs found within a poll interval into a single emission. When `false`, each log is emitted on its own.

### fromBlock

* **Type:** `bigint`

Block number from which to start watching for logs.

### poll

* **Type:** `boolean`

Whether to poll for new logs instead of using a subscription. Defaults to `true` when the transport cannot subscribe or `fromBlock` is provided.

### pollingInterval

* **Type:** `number`
* **Default:** `client.pollingInterval`

Polling frequency (in ms).
