> ## 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 110+ 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.
> For Portal availability errors, stalled streams, or rate limiting, read https://status.sqd.dev/status.md. The status index at https://status.sqd.dev/llms.txt explains network and plan filters.
> Every page on this site is available as Markdown by appending .md to its URL.

# Migrate a squid to Portal

> Move a Substrate squid from the v2 gateway to Portal with substrate-processor 9.

This guide moves a Substrate squid that reads historical data through a v2 gateway (`.setGateway()`, `.setArchive()` or `.setDataSource({archive})`) to SQD Portal. It is mostly a configuration change: `@subsquid/substrate-processor` 9 replaces the gateway with `.setPortal()` and keeps the rest of the API, so your handlers, types and database stay as they are. One change in request matching can affect handlers; see [Behaviour differences](#behaviour-differences).

The chain RPC endpoint keeps its role. [`SubstrateBatchProcessor`](../../reference/substrate-processor/general) still needs it for runtime metadata, and it still serves the blocks above the Portal's finalized head, so a real-time squid stays real-time.

## Prerequisites

* A squid based on `@subsquid/substrate-processor` 8.x that calls `.setGateway()`, `.setArchive()` or `.setDataSource()`
* Node.js 22+
* An archive RPC endpoint for your chain, as before
* The Portal dataset of your network: `https://portal.sqd.dev/datasets/<slug>`. The slug is the network name of the old gateway URL; check that the network has a dataset on the [Substrate networks page](https://docs.sqd.dev/en/data/substrate.md).

## Migration steps

**Jump to:** [Networks without a Portal dataset](#networks-without-a-portal-dataset) · [Behaviour differences](#behaviour-differences) · [Typegen metadata](#typegen-metadata) · [Common errors](#common-errors-substrate)

**1. Upgrade the processor**

From your squid's folder, install the 9.x release:

```bash theme={"system"}
npm install @subsquid/substrate-processor@^9
```

Version 9 removes `.setGateway()`, `.setArchive()`, `.setDataSource()` and the `GatewaySettings`/`ArchiveSettings`/`DataSource` types, so the project won't compile until the next step is done.

**2. Replace the gateway with Portal**

Point the processor at the Portal dataset instead of the gateway:

```diff theme={"system"}
 export const processor = new SubstrateBatchProcessor()
-  .setGateway('https://v2.archive.subsquid.io/network/kusama')
+  .setPortal('https://portal.sqd.dev/datasets/kusama')
   .setRpcEndpoint({
     url: assertNotNull(process.env.RPC_KUSAMA_HTTP),
     rateLimit: 10
   })
```

> [accordion] Using the deprecated .setDataSource()? Split it in two.
>
> `.setDataSource()` is gone in version 9. Its `chain` setting becomes `.setRpcEndpoint()`:
>
> ```diff theme={"system"}
> -  .setDataSource({
> -    archive: 'https://v2.archive.subsquid.io/network/astar-substrate',
> -    chain: 'https://rpc.astar.network'
> -  })
> +  .setPortal('https://portal.sqd.dev/datasets/astar-substrate')
> +  .setRpcEndpoint('https://rpc.astar.network')
> ```

> [accordion] Passing gateway settings (apiKey, requestTimeout)? Use PortalSettings.
>
> `.setPortal()` accepts a URL or a [`PortalSettings`](../../reference/substrate-processor/general#set-portal) object. `PortalSettings` has no `apiKey` setting, and the processor no longer reads `SQD_API_KEY`, so drop both:
>
> ```diff theme={"system"}
> -  .setGateway({
> -    url: 'https://v2.archive.subsquid.io/network/kusama',
> -    apiKey: process.env.SQD_API_KEY,
> -    requestTimeout: 60_000,
> -  })
> +  .setPortal({
> +    url: 'https://portal.sqd.dev/datasets/kusama',
> +    requestTimeout: 60_000,
> +  })
> ```
>
> A Portal that expects a key takes it as a header: `headers: {'x-api-key': process.env.PORTAL_API_KEY}`. The public Portal is shared capacity. If you need guaranteed capacity, ask in the [SquidDevs Telegram chat](https://t.me/HydraDevs).

> [accordion] If your squid processes finalized blocks only (.setRpcDataIngestionSettings(\{disabled: true}) or .useArchiveOnly())
>
> Nothing changes. With RPC ingestion disabled, the processor handles only the finalized blocks served by the Portal and keeps following the Portal's finalized head. The RPC endpoint is still required for runtime metadata.

**3. Build and smoke-test**

Build the squid and run it locally:

```bash theme={"system"}
npm run build
node -r dotenv/config lib/main.js
```

The processor logs `using archive data source` while it reads from the Portal, then `using chain RPC data source` once it reaches the Portal's head.

**4. Deploy**

A squid that already synced from the gateway does **not** need a re-sync: the processor state in the database doesn't depend on the data source, and the Portal serves the same blocks and items. Deploy the new version over the old one.

If your squid is deployed to the [Cloud](https://docs.sqd.dev/en/cloud), you can also deploy into a new slot first and switch the production tag once it's ready; see [the slots and tags guide](https://docs.sqd.dev/en/cloud/resources/slots-and-tags.md#zero-downtime-updates).

## Networks without a Portal dataset

If the [Substrate networks page](https://docs.sqd.dev/en/data/substrate.md) has no Portal dataset for your network, drop the gateway call and keep `.setRpcEndpoint()`. The processor then reads every block from the chain RPC:

```diff theme={"system"}
 export const processor = new SubstrateBatchProcessor()
-  .setGateway('https://v2.archive.subsquid.io/network/<network>')
   .setRpcEndpoint(process.env.RPC_ENDPOINT)
```

If the squid disabled RPC ingestion with `.setRpcDataIngestionSettings({disabled: true})` or `.useArchiveOnly()`, remove that call too: with RPC ingestion disabled the processor requires a Portal and stops with `Portal is required when RPC data ingestion is disabled`.

A synced squid continues from where it stopped. Syncing a new squid this way takes much longer than from a Portal, since every historical block is fetched over RPC.

## Behaviour differences

* **Typed requests without filters.** In version 9, [`addEvmLog({})`](../../reference/substrate-processor/data-requests#addevmlog), [`addEthereumTransaction({})`](../../reference/substrate-processor/data-requests#addethereumtransaction) and [`addContractsContractEmitted({})`](../../reference/substrate-processor/data-requests#addcontractscontractemitted) without filters select only `EVM.Log` events, `Ethereum.transact` calls and `Contracts.ContractEmitted` events respectively, from the Portal and from RPC alike. In version 8, RPC ingestion matched every event or call for them. If your handler relied on those extra items, request them explicitly with [`addEvent()`](../../reference/substrate-processor/data-requests#events) or [`addCall()`](../../reference/substrate-processor/data-requests#calls).
* **Gear `MessageQueued` requests with program ids.** For [`addGearMessageQueued({programId})`](../substrate/gear), the processor requests all `Gear.MessageQueued` events of the matching blocks from the Portal and filters them by program id itself. The result is the same as from RPC ingestion, but the squid downloads the messages of other programs too.
* **Field selection.** The Portal returns only the selected fields. The processor always selects the fields it needs internally, so your [field selection](https://docs.sqd.dev/en/sdk/squid-sdk/substrate/reference/substrate-processor/field-selection.md) stays the same.

## Typegen metadata

The `specVersions` setting of [`squid-substrate-typegen`](../../reference/substrate-typegen) often points at a metadata service on the v2 gateway host (`https://v2.archive.subsquid.io/metadata/<network>`). To stop depending on it, generate the spec versions file from your chain RPC with the [metadata explorer](https://docs.sqd.dev/en/sdk/squid-sdk/substrate/reference/substrate-typegen.md#generate-spec-versions-from-rpc) and point `specVersions` at the file. Typegen only runs at development time, so this doesn't affect a running squid.

## Common errors (Substrate)

| Symptom | Root cause | Fix |
| - | - | - |
| `Property 'setGateway' does not exist on type 'SubstrateBatchProcessor'` (or `setArchive`/`setDataSource`) | Version 9 replaced the gateway with Portal | Use `.setPortal()` (see *Replace the gateway with Portal*) |
| `Module '"@subsquid/substrate-processor"' has no exported member 'GatewaySettings'` | Same | Use `PortalSettings` |
| `Object literal may only specify known properties, and 'apiKey' does not exist in type 'PortalSettings'` | `PortalSettings` has no `apiKey` setting | Drop `apiKey`; a Portal that expects a key takes `headers: {'x-api-key': ...}` |
| `Chain RPC endpoint is always required. Use .setRpcEndpoint() to specify it.` | RPC is required on Substrate for runtime metadata | Keep `.setRpcEndpoint()` |
| `Portal is required when RPC data ingestion is disabled` | RPC ingestion is disabled and no Portal is set | Add `.setPortal()` or enable RPC ingestion |
| HTTP 404 from `portal.sqd.dev` | The network has no Portal dataset | Index from RPC alone, see [Networks without a Portal dataset](#networks-without-a-portal-dataset) |

## Reference template (Substrate)

> [card] [squid-substrate-template](https://github.com/subsquid-labs/squid-substrate-template)
>
> Kusama transfers squid with a Portal data source and RPC, the setup this guide produces

## Next steps (Substrate)

> [card] [General settings](https://docs.sqd.dev/en/sdk/squid-sdk/substrate/reference/substrate-processor/general.md)
>
> All `SubstrateBatchProcessor` data source settings

> [card] [Unfinalized blocks](https://docs.sqd.dev/en/sdk/squid-sdk/substrate/guides/advanced/unfinalized-blocks.md)
>
> How the processor follows the chain head through RPC


## Related topics

- [Migrate a squid to Portal](https://docs.sqd.dev/en/sdk/squid-sdk/evm/guides/migration/gateway-to-portal.md)
- [How to use your dedicated Portal with a key](https://docs.sqd.dev/en/sdk/squid-sdk/evm/guides/migration/portal-api-key.md)
- [EVM Portal stream](https://docs.sqd.dev/en/sdk/squid-sdk/evm/reference/evm-stream.md)
- [Quickstart](https://docs.sqd.dev/en/sdk/squid-sdk/solana/quickstart.md)
- [Changelog](https://docs.sqd.dev/changelog.md)


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