Skip to content

A simple Binance subgraph that uses Subsquid Network as its data source

Notifications You must be signed in to change notification settings

venomy420/simple-busd-subgraph

 
 

Repository files navigation

Subsquid Logo

docs.rs Discord

Website | Docs | Discord

Subsquid Network FAQ

Deploy a simple BUSD subgraph

This is a quest to run a simple subgraph using the data from the permissionless 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 the squid:

I. Install dependencies: Node.js, Docker, Git.

On Windows
  1. Enable Hyper-V.
  2. Install Docker for Windows.
  3. Install NodeJS LTS using the official installer.
  4. 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
  1. Install Docker for Mac.
  2. Install Git using the installer or by other means.
  3. 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.

II. Run the subgraph

  1. 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
  2. Press "Get Key" button in the quest card to obtain the busdSubgraph.key key file. Save it to the ./query-gateway/keys subfolder of the squid folder. The file will be used by the query gateway container.

  3. Start all 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.

  4. Randomize the starting block of the subgraph by running:

    yarn run randomize
  5. 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 by yarn run deploy-local again.

  6. Leave the syncing process to run overnight. Once done, shut down the containers with

    docker compose down

Quest Info

Category Skill Level Time required (minutes) Max Participants Reward Status
Squid Deployment $\textcolor{green}{\textsf{Simple}}$ ~720 - $\textcolor{red}{\textsf{750tSQD}}$ open

Acceptance critera

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.

About this subgraph

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 gateway
  • config.toml - config for the Graph node
  • docker-compose.yml - definition of all the involved containers, including the one running subsquid-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
  }
}

About

A simple Binance subgraph that uses Subsquid Network as its data source

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%