This is an updated quest to run a simple subgraph using the data from the permissionless Phase 2 Subsquid Network. The subgraph used was generated with graph init
; it indexes BUSD transfers on Binance mainnet.
You can find more info on using Subsquid Network to run subgraphs at the Subsquid Firehose docs page.
Here is how to run it:
On Windows
- 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.
On Mac
- 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.
On Linux
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.
-
Download the subgraph, enter its folder and install the dependencies
git clone https://github.com/subsquid-quests/simple-busd-subgraph
cd simple-busd-subgraph
yarn install
Important
If you're on Windows, the terminal opens in C:\Windows\system32
by default. Do not download your squid there, navigate someplace else.
-
Press "Get Key" button in the quest card to obtain the
busdSubgraphPhaseTwo.key
key file. Save it to the./query-gateway/keys
subfolder of the squid folder. The file will be used to identify your local query gateway when locking tSQD to allocate bandwidth and as it operates. -
Get the peer ID of your future gateway by running:
yarn run get-peer-id
-
Register your future gateway using this page.
- Use the peer ID you obtained in the previous step.
- Leave the "Publicly available" switch disabled.
-
Lock 10 tSQD by selecting your gateway on this page, clicking "Get CU" and submitting the form. Once done, you will begin getting computation units (CUs) once every epoch (~15 minutes).
The "Lock blocks duration" field lets you tune the length of time during which you'll be able to query the network, measured in blocks of Arbitrum Sepolia's L1 (that is, Ethereum Sepolia). The minumum is five hours, but you can opt to lock for longer if you intend to work on the quest over multiple days.
Time Blocks 5 hours (minimum) 1500 24 hours 7200 72 hours 21600 Be aware that you'll need to unlock your tokens manually after the end of this period. The tokens you get back will be used in subsequent quests.
If the locking period expires before you finish your work, simply unlock your tokens, then lock them again.
-
Wait for about 15 minutes. This is the time it takes for Subsquid Network to enter a new epoch, at the beginning of which CUs will be allocated towards your gateway.
-
Start the gateway and the rest of the services required to run the subgraph as Docker containers:
docker compose up -d
Wait for about a couple of minutes before proceeding to the next step.
-
Randomize the starting block of the subgraph by running:
yarn run randomize
-
Create and deploy the subgraph:
yarn run create-local
yarn run deploy-local
To check if the subgraph is successfully deployed, check the output of
docker logs -f --tail 10 simple-busd-subgraph-graph-node-1
It should contain lines like this:
Dec 10 18:49:54.966 INFO Done processing trigger, gas_used: 79221480, data_source: busd, handler: handleTransfer, total_ms: 1, transaction: 0xb0ab…129e, address: 0x55d3…7955, signature: Transfer(indexed address,indexed address,uint256), sgd: 1, subgraph_id: QmQwLxHMw4Mf7VSfVfw66pKcySKRFGfh2freN7MJbbp7br, component: SubgraphInstanceManager Dec 10 18:49:54.968 INFO Done processing trigger, gas_used: 79221480, data_source: busd, handler: handleTransfer, total_ms: 1, transaction: 0xac49…4960, address: 0x55d3…7955, signature: Transfer(indexed address,indexed address,uint256), sgd: 1, subgraph_id: QmQwLxHMw4Mf7VSfVfw66pKcySKRFGfh2freN7MJbbp7br, component: SubgraphInstanceManager
Note that it might take a few minutes before the subgraph gets to that stage.
If you get an error like this:
✖ Failed to deploy to Graph node http://localhost:8020/: network not supported by registrar: no network bsc found on chain ethereum
simply restart the containers with
docker compose down
docker compose up -d
and run
yarn run create-local
followed byyarn run deploy-local
again. -
Leave the syncing process to run overnight. Once done, shut down the containers with
docker compose down
Category | Skill Level | Time required (minutes) | Max Participants | Reward | Status |
---|---|---|---|---|---|
Squid Deployment | ~720 | - | open |
Sync this subgraph for about 8-12 hours using the key from the quest card. The syncing progress is tracked by the amount of data the subgraph has retrieved from Subsquid Network.
Here is the exact Graph CLI command that was used to generate the subgraph used for this quest:
graph init --from-contract 0x55d398326f99059fF775485246999027B3197955 --network bsc simple-busd-subgraph --allow-simple-name
To make the subgraph ingest its data from the decentralized and permissionless version of Subsquid Network, we added the following files
query-gateway/config/gateway-config.yml
- config for the decentralized Subsquid Network gatewayconfig.toml
- config for the Graph nodedocker-compose.yml
- definition of all the involved containers, including the one runningsubsquid-firehose
Once the subgraph is up and running, it will expose its GraphQL API (with a GraphiQL playground) at http://localhost:8000/subgraphs/name/simple-busd-subgraph/. Check its status by running the following query:
{
_meta {
block {
number
hash
timestamp
}
deployment
hasIndexingErrors
}
}