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

# Substrate Batch General Settings

> General settings for Squid SDK SubstrateBatchProcessor.

<Tip>
  The method documentation is also available inline and can be accessed via suggestions in most IDEs.
</Tip>

The following setters configure the global settings of `SubstrateBatchProcessor`. They return the modified instance and can be chained.

Calling [`setRpcEndpoint()`](#set-rpc-endpoint) is a hard requirement on Substrate, as chain RPC is used to retrieve chain metadata. Adding a [SQD Network gateway](/en/data/substrate) with [`setGateway()`](#set-gateway) is optional but highly recommended, as it greatly reduces RPC usage.

To reduce it further, you can explicitly disable [RPC ingestion](../../guides/advanced/unfinalized-blocks) by calling [`setRpcDataIngestionSettings(\{ disabled: true \})`](#set-rpc-data-ingestion-settings): in this scenario the RPC will only be used for metadata retrieval and to perform any direct RPC queries you might be doing in your squid code. This will, however, introduce a delay of a few thousands of blocks between the chain head and the highest block available to your squid.

<Warning>
  SQD Network v2 gateways require an API key. Set `SQD_API_KEY` in the process environment or pass `apiKey` in `GatewaySettings`.
</Warning>

<h3 id="set-gateway">
  `setGateway(url: string | GatewaySettings)`
</h3>

Adds a [SQD Network](/en/network/overview) data source. The argument is either a string URL of a SQD Network gateway or

```typescript theme={"system"}
{
  url: string // gateway URL
  apiKey?: string // defaults to process.env.SQD_API_KEY
  requestTimeout?: number // in milliseconds
}
```

See [Substrate gateways](/en/data/substrate).

<h3 id="set-rpc-endpoint">
  `setRpcEndpoint(rpc: ChainRpc)`
</h3>

Adds a RPC data source. If added, it will be used for

* [RPC ingestion](../../guides/advanced/unfinalized-blocks) (unless explicitly disabled with [`setRpcDataIngestionSettings()`](#set-rpc-data-ingestion-settings))
* any direct RPC queries you make in your squid code

A node RPC endpoint can be specified as a string URL or as an object:

```typescript theme={"system"}
type ChainRpc = string | {
  url: string // http, https, ws and wss are supported
  capacity?: number // num of concurrent connections, default 10
  maxBatchCallSize?: number // default 100
  rateLimit?: number // requests per second, default is no limit
  requestTimeout?: number // in milliseconds, default 30_000
  headers?: Record<string, string> // http headers
}
```

Setting `maxBatchCallSize` to `1` disables batching completely.

<Tip>
  We recommend using private endpoints for better performance and stability of your squids. For SQD Cloud deployments you can use the [RPC addon](/en/cloud/resources/rpc-proxy). If you use an external private RPC, keep the endpoint URL in a [Cloud secret](/en/cloud/resources/env-variables#secrets).
</Tip>

<h3 id="set-data-source">
  `setDataSource(ds: \{archive?: string, chain?: ChainRpc\})` (deprecated)
</h3>

Replaced by [`setGateway()`](#set-gateway) and [`setRpcEndpoint()`](#set-rpc-endpoint).

<h3 id="set-rpc-data-ingestion-settings">
  `setRpcDataIngestionSettings(settings: RpcDataIngestionSettings)`
</h3>

Specify the [RPC ingestion](../../guides/advanced/unfinalized-blocks) settings.

```typescript theme={"system"}
type RpcDataIngestionSettings = {
  disabled?: boolean
  headPollInterval?: number
  newHeadTimeout?: number
}
```

Here,

* `disabled`: Explicitly disables data ingestion from an RPC endpoint. **RPC remains required on Substrate because `SubstrateBatchProcessor` uses it for metadata.** The processor continues to follow the gateway dataset head; it does not terminate just because it catches up.
* `headPollInterval`: Poll interval for new blocks in milliseconds. Poll mechanism is used to get new blocks via HTTP connections. Default: 5000.
* `newHeadTimeout`: When ingesting from a websocket, this setting specifies the timeout in milliseconds after which the connection will be reset and subscription re-initiated if no new blocks were received. Default: no timeout.

<h3 id="set-block-range">
  `setBlockRange(\{from: number, to?: number\})`
</h3>

Limits the range of blocks to be processed. When the upper bound is specified, processor will terminate with exit code 0 once it reaches it.

Note that block ranges can also be specified separately for each data request. This method sets global bounds for all block ranges in the configuration.

<h3 id="set-finality-confirmation">
  `setFinalityConfirmation(nBlocks: number)`
</h3>

Overrides finalized-head tracking with a fixed distance from the chain head. The default uses `chain_getFinalizedHead`. Setting `0` treats all blocks as final.

<h3 id="include-all-blocks">
  `includeAllBlocks(range?: \{from: number, to?: number\})`
</h3>

By default, processor will fetch only blocks which contain requested items. This method modifies such behavior to fetch all chain blocks. Optionally a range of blocks can be specified for which the setting should be effective.

<h3 id="set-types-bundle">
  `setTypesBundle(bundle: string | OldTypesBundle | OldSpecsBundle | PolkadotjsTypesBundle)`
</h3>

Sets a [types bundle](https://substrate.stackexchange.com/a/1231/4655).

Types bundle is only required for historical blocks which have metadata version below 14 and only if we don't have built-in support for the chain in question. Most chains listed in the [polkadot.js app](https://polkadot.js.org/apps/#/explorer) are supported.

SQD project has its own types bundle format, however, most of polkadotjs types bundles will work as well.

Types bundles can be specified in 2 different ways:

1. as a name of a JSON file:
   ```typescript theme={"system"}
   processor.setTypesBundle('typesBundle.json')
   ```
2. as an [`OldTypesBundle`/`OldSpecsBundle`](https://github.com/subsquid/squid-sdk/blob/master/substrate/substrate-runtime/src/metadata/old/types.ts) or [`PolkadotjsTypesBundle`](https://github.com/subsquid/squid-sdk/blob/master/substrate/substrate-runtime/src/metadata/old/types.ts) object:
   ```typescript theme={"system"}
   // OldTypesBundle object
   processor.setTypesBundle({
     types: {
       Foo: 'u8'
     }
   })
   ```

There a [mini-guide](../../guides/substrate/types-bundle-miniguide) on how to obtain type bundles for Substrate chains without relying on SQD tools.

<h3 id="set-prometheus-server">
  `setPrometheusServer(server: PrometheusServer)`
</h3>

Sets a custom Prometheus server from `@subsquid/util-internal-processor-tools`.

<h3 id="set-prometheus-port">
  `setPrometheusPort(port: string | number)` (deprecated)
</h3>

Sets the port for the built-in Prometheus metrics server. Use `setPrometheusServer()` for new code. `PROCESSOR_PROMETHEUS_PORT` takes precedence over `PROMETHEUS_PORT`; if neither is set, the processor selects an ephemeral port.
