Where are you starting from?
- Your squid uses
.setGateway()andEvmBatchProcessor(a v2 squid). Migrate it to the public Portal first by following Migrate a squid to Portal, then come back here. - Your squid uses
DataSourceBuilderfrom@subsquid/evm-streamwith.setPortal('https://portal.sqd.dev/...'). Read on.
Prerequisites
- The base URL of your dedicated Portal and an API key for it. See Portal pricing for the plans that come with a key.
- Any released version of
@subsquid/evm-stream(0.0.1or later). All of them accept thehttpoption shown below and send its headers with every Portal request. The only exception is the early0.0.1-2-0.3887d2prerelease, whose.setPortal()takes just a URL string or aPortalClient. If yourpackage.jsonpins a prerelease, update to the latest version first:
Migration steps
1
Pass the URL and the key to .setPortal()
Switch The dataset slug (
If you construct a
.setPortal() from the URL string form to the options object form. The dataset URL is now built from your Portal’s base URL, and the key goes into the x-api-key header:ethereum-mainnet here) is the same as on the public Portal. Portal also accepts the key as Authorization: Bearer <key>; see Presenting an API key.Already passing http options, or a PortalClient instance?
Already passing http options, or a PortalClient instance?
http replaces the HTTP client settings as a whole. If you already set other options there (e.g. retryAttempts), add headers next to them:PortalClient yourself and pass it to .setPortal(), set the same url and http options on its constructor instead.2
Read the URL and the key from the environment
Do not hardcode the key. Read both values from environment variables and fail early if either is missing:
@subsquid/util-internal is already installed as a dependency of @subsquid/evm-stream. Add it to your package.json explicitly (npm i @subsquid/util-internal) if you prefer to import only direct dependencies.3
Set the variables locally
Add the variables to the
.env file of your squid:.env
sqd process loads .env automatically. If you run the compiled squid directly, load it with node --require=dotenv/config lib/main.js. Keep .env out of version control once it holds the key.4
Set the variables in SQD Cloud
Optional Only for squids deployed to SQD Cloud.Store the key as an organization secret:Then expose both variables to the processor in
squid.yaml:squid.yaml
5
Smoke-test and deploy
Build and start the squid:A missing variable stops the squid at startup with the message from
assertNotNull. A key that the Portal rejects fails the first request with a 403; the error code tells a missing key from a wrong or expired one (see Error codes).The data served by your dedicated Portal is the same as on the public one, so there is no need to re-sync. Re-deploy the squid without resetting its database.Complete example
src/main.ts (data source part)
src/main.ts (data source part)
run() call and the batch handler) is unchanged. For the full file, see the squid-evm-rt-template.