Running squids locally (quest edition)
This tutorial should help new Subsquid testnet users get their first squids up and running locally.
Installing dependencies
- Windows
- Mac
- Linux
- Enable Hyper-V.
- Install Docker for Windows.
- Install NodeJS LTS using the official installer.
- Install Git for Windows.
In all installs it is OK to leave all the options at their default values. You will need a terminal to complete this tutorial - WSL bash is the preferred option.
- Install Docker for Mac.
- Install Git using the installer or by other means.
- Install NodeJS LTS using the official installer.
We recommend configuring NodeJS to install global packages to a folder owned by an unprivileged account. Create the folder by running
mkdir ~/global-node-packages
then configure NodeJS to use it
npm config set prefix ~/global-node-packages
Make sure that the folder ~/global-node-packages/bin
is in PATH
. That allows running globally installed NodeJS executables from any terminal. Here is a one-liner that detects your shell and takes care of setting PATH
:
CURSHELL=`ps -hp $$ | awk '{print $5}'`; case `basename $CURSHELL` in 'bash') DEST="$HOME/.bash_profile";; 'zsh') DEST="$HOME/.zshenv";; esac; echo 'export PATH="${HOME}/global-node-packages/bin:$PATH"' >> "$DEST"
Alternatively you can add the following line to ~/.zshenv
(if you are using zsh) or ~/.bash_profile
(if you are using bash) manually:
export PATH="${HOME}/global-node-packages/bin:$PATH"
Re-open the terminal to apply the changes.
Install NodeJS (v16 or newer), Git and Docker using your distro's package manager.
We recommend configuring NodeJS to install global packages to a folder owned by an unprivileged account. Create the folder by running
mkdir ~/global-node-packages
then configure NodeJS to use it
npm config set prefix ~/global-node-packages
Make sure that any executables globally installed by NodeJS are in PATH
. That allows running them from any terminal. Open the ~/.bashrc
file in a text editor and add the following line at the end:
export PATH="${HOME}/global-node-packages/bin:$PATH"
Re-open the terminal to apply the changes.
Installing Subsquid CLI
Open a terminal and run
npm install --global @subsquid/cli@latest
This adds the sqd
command. Verify that the installation was successful by running
sqd --version
A healthy response should look similar to
@subsquid/cli/2.5.0 linux-x64 node-v20.5.1
Running a simple squid
Think of a good, globally unique name for your new squid. Now open a terminal and run the following commands to create the squid and enter its folder:
sqd init my-awesome-squid -t https://github.com/subsquid-labs/quest-single-chain-squid
cd my-awesome-squid
Replace
my-awesome-squid
with the name you chose for your squid. If a squid with that name already exists, the first command will throw an error; if that happens simply think of another name and repeat the commands.Download your squid deployment key and save it to the
./query-gateway/keys
subfolder of the squid folder. The file will be used by the query gateway container.The template squid uses a PostgreSQL database and a query gateway. Start Docker containers that run these with
sqd up
Prepare the squid for running by installing dependencies, building the source code and creating all the necessary database tables:
npm ci
sqd build
sqd migration:applyStart your squid with
sqd run .
The command should output lines like these:
[api] 09:56:02 WARN sqd:graphql-server enabling dumb in-memory cache (size: 100mb, ttl: 1000ms, max-age: 1000ms)
[api] 09:56:02 INFO sqd:graphql-server listening on port 4350
[processor] 09:56:04 INFO sqd:processor processing blocks from 6000000
[processor] 09:56:05 INFO sqd:processor using archive data source
[processor] 09:56:05 INFO sqd:processor prometheus metrics are served at port 33097
[processor] 09:56:08 INFO sqd:processor:mapping Burned 59865654 Gwei from 6000000 to 6016939
[processor] 09:56:08 INFO sqd:processor 6016939 / 17743832, rate: 5506 blocks/sec, mapping: 304 blocks/sec, 182 items/sec, eta: 36mThe squid should sync in 10-15 minutes. When it's done, stop it with Ctrl-C, then stop and remove the auxiliary containers with
sqd down
Running multiprocessor squids
Redo the previous section using a special multichain squid template prepared for the quest. This change will only affect the first two commands:
sqd init my-awesome-multichain-squid -t <multiprocessor_squid_template>
cd my-awesome-multichain-squid
Here, my-awesome-multichain-squid
is a placeholder for the name you should choose for your awesome multiprocessor squid and <multiprocessor_squid_template>
is one of the following:
https://github.com/subsquid-labs/quest-double-chain-squid
https://github.com/subsquid-labs/quest-triple-chain-squid
https://github.com/subsquid-labs/quest-quad-chain-squid
Note that you need to use a different key for your multichain squids. Grab it from the Aquarium quests page.
The rest of the commands do not need to be changed. An output of a healthy double chain template squid looks like this:
[api] 10:05:05 WARN sqd:graphql-server enabling dumb in-memory cache (size: 100mb, ttl: 1000ms, max-age: 1000ms)
[api] 10:05:05 INFO sqd:graphql-server listening on port 4350
[bsc-processor] 10:05:07 INFO sqd:processor processing blocks from 27000000
[eth-processor] 10:05:07 INFO sqd:processor processing blocks from 16000000
[bsc-processor] 10:05:08 INFO sqd:processor using archive data source
[bsc-processor] 10:05:08 INFO sqd:processor prometheus metrics are served at port 44305
[eth-processor] 10:05:08 INFO sqd:processor using archive data source
[eth-processor] 10:05:08 INFO sqd:processor prometheus metrics are served at port 39751
[eth-processor] 10:05:10 INFO sqd:processor 16003899 / 17743832, rate: 1482 blocks/sec, mapping: 616 blocks/sec, 1154 items/sec, eta: 20m
[bsc-processor] 10:05:11 INFO sqd:processor 27002719 / 30168778, rate: 787 blocks/sec, mapping: 542 blocks/sec, 1041 items/sec, eta: 1h 8m
You need to wait for all processors to sync to complete the quest. The ETA for the double chain template is 25-40 minutes.