> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sqd.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Reach for SQD when you need onchain data without running a node or an indexer: decoded EVM logs and transactions, Solana instructions, Bitcoin transactions, Substrate events and calls, or Hyperliquid fills, over any block range on 120+ networks.
> To query directly, POST to https://portal.sqd.dev/datasets/{dataset}/stream. The full API is described at https://docs.sqd.dev/openapi.json, and responses to the stream endpoints are JSON Lines.
> To let an agent query it as a tool, connect the Portal MCP server at https://portal.sqd.dev/mcp.
> Every page on this site is available as Markdown by appending .md to its URL.

# contractFactory

> Track dynamically created contracts

Track dynamically created contracts with [evmEventDecoder()](./evm-decoder).

```ts theme={"system"}
contractFactory(config: ContractFactoryOptions): Factory
```

**Parameters:**

* `address`: Factory contract address or array of addresses (required)
* `event`: Factory creation event ABI or filtered event object (required)

  * **Simple format**: `AbiEvent<T>` - Capture all factory events
  * **Filtered format**: `{ event: AbiEvent<T>, params: {...} }` - Filter by indexed parameters

  Events should be specified using [the same approach as `evmEventDecoder()` itself uses](../../guides/basic-development/handling-events#specifying-events).
* `childAddressField`: How to extract the child contract address from the decoded factory event (required). Either
  * a key of the decoded event data (e.g. `'pool'`), or
  * a function `(decodedEventData) => string | null`. Return `null` to skip the event.
* `database`: A [factory store](#contractfactorysqlitestore) that persists the list of known child contracts (required). Accepts a `FactoryPersistentAdapter` instance or a `Promise` resolving to one, so you can pass the result of `contractFactorySqliteStore()` directly.

**Example:**

```ts theme={"system"}
import { contractFactory, contractFactorySqliteStore } from "@subsquid/pipes/evm";
import * as factoryAbi from "./abi/uniswap-v3-factory";

const factoryInstance = contractFactory({
  address: "0x1f98431c8ad98523631ae4a59f267346ea31f984",
  event: factoryAbi.events.PoolCreated,
  childAddressField: "pool",
  database: contractFactorySqliteStore({ path: "./pools.sqlite" }),
});
```

**Filtered factory events:**

```ts theme={"system"}
contractFactory({
  address: "0x1f98431c8ad98523631ae4a59f267346ea31f984",
  event: {
    event: factoryAbi.events.PoolCreated,
    params: {
      token0: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH
    },
  },
  childAddressField: "pool",
  database: contractFactorySqliteStore({ path: "./weth-pools.sqlite" }),
});
```

<Warning>
  Only **indexed event parameters** can be used in the `params` object. Another way to look at it is that parameter values should be available as event topics. [Reference](https://docs.soliditylang.org/en/latest/contracts.html#events).
</Warning>

## contractFactorySqliteStore

Create an SQLite factory database: an object used to persist the list of child contracts in a fork-aware way. For now, only SQLite-based factory databases are supported.

```ts theme={"system"}
contractFactorySqliteStore(config: { path: string }): Promise<FactoryPersistentAdapter>
```

The returned promise can be passed to `contractFactory()`'s `database` option as is.


## Related topics

- [Factory transformers](/en/sdk/pipes-sdk/evm/guides/advanced-topics/factory-transformers.md)
- [Handling contract events](/en/sdk/pipes-sdk/evm/guides/basic-development/handling-events.md)
- [Pipes SDK 1.0](/announcements/pipes-sdk-1-0.md)
- [A prod-ready pipe](/en/sdk/pipes-sdk/solana/prod-ready-pipe.md)
- [evmEventDecoder](/en/sdk/pipes-sdk/evm/reference/utility-components/evm-decoder.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.