DEV Community

Cover image for Getting Started with SubQuery Managed Service
geniusyinka
geniusyinka

Posted on

Getting Started with SubQuery Managed Service

Getting data from the blockchain can be difficult, slow, and painful. This is the exact problem that SubQuery solves.

SubQuery is an open-source blockchain indexer that makes it easy to work with blockchain data. It allows developers to transform blockchain data into a queryable state so that it can be used in decentralized applications simply via APIs.

While you can run your subquery projects locally or on any cloud provider of your choosing, SubQuery also provides a managed hosting service to host your projects and serve your applications. In this article, I will explore SubQuery Managed Service and also deploy a basic project atop the service.

Introducing SubQuery Managed Service

SubQuery Managed service is an enterprise-level hosting solution provided by SubQuery for developers to publish indexers without the burden of managing any indexing infrastructure. It offers a free tier to host your first two projects before upgrading to a paid plan.

Benefits of SubQuery Managed Service

Some of the benefits of hosting via the Managed Service are:

  1. 99.9% Uptime Hosting: SubQuery is designed to provide reliable and consistent uptime for your applications.
  2. Dedicated Databases: For production applications, SubQuery offers an option to upgrade to a private dedicated database for your indexing needs.
  3. Advanced monitoring and analytics: SubQuery provides a detailed analytics panel to monitor the health of your applications.
  4. Intelligent multi-cluster routing: SubQuery will direct traffic to the most efficient cluster based on location and load.

How to Publish Indexers to the Managed Service

Let's explore how to deploy a subquery project to the managed service.

To demonstrate, we will publish the [osmosis-dex-data](https://github.com/subquery/cosmos-subql-starter/tree/main/Osmosis/osmosis-dex-data) project by SubQuery in this guide. You can follow the same steps to publish your project. If you do not have a project setup, check out the SubQuery documentation on how to set up a project locally on your machine.

Step 1: Create an account

The first step is to create a Managed Service account. Go to SubQuery Managed Service to register or log in if you already have an account.

Image description

This is important so you can grab your SUBQL_ACCESS_TOKEN, which is vital for the next step in the process.

Step 2: Configure Environment Variables

Now that you have created an account. Let's grab our private SUBQL_ACCESS_TOKEN via the UI.

Select your profile at the top right of the navigation menu. Select “Refresh Token” from the drop-down.

Image description

Copy the token from the pop-up that appears.

Image description

Next, create and set an environment variable either in your local config file or from your terminal,

// For PC
SET SUBQL_ACCESS_TOKEN=<token>

//For Mac/Linux
export SUBQL_ACCESS_TOKEN=<token>
Enter fullscreen mode Exit fullscreen mode

Replace <token> with the token you copied from the UI.

Note: You will need to update your enviroment variables everytime you click on “Refresh Token” on your dashboard UI.

Step 3: Publish your SubQuery project to IPFS

Now that we've configured the environment variables, the next step is to push your codebase to IPFS. IPFS makes it available for everyone and reduces the dependency on centralized services like GitHub.

In your terminal, run the command below:

// Publish it from your project's root directory
subql publish
Enter fullscreen mode Exit fullscreen mode

After successfully publishing the project, you should see a confirmation message in your terminal.

Building and packing code... done
Uploading SupQuery project to IPFS
SubQuery Project uploaded to IPFS: QmSU48e2FfCAYB151eJdGc7kDYZBJRXgu6qkUf5Gv48zMr  //---CID
Enter fullscreen mode Exit fullscreen mode

Copy the CID and save it for later.

Step 4: Create a SubQuery Project

Your SubQuery project is where you manage all your hosted projects uploaded to the SubQuery platform. You can create, delete, and even upgrade projects from the dashboard.

On your dashboard, Select “Create your SubQuery Project”.

Image description

You'll be taken to the new project form. Here, you can fill in the project name, description, database type, and project visibility status.

Image description

Project Logo: You can upload a custom logo or leave the default image.

Project Name: Give your project a name based on your project or the data you are indexing.

Description: A demonstration for an article on SubQuery's Managed Service.

Database: “Shared Database”. You will need to upgrade to a paid plan to access dedicated databases to host production SubQuery projects. For this demonstration and most experimentation, the “Share Database” option is just fine.

Visible in Explorer: If selected, this will show the project from the public SubQuery explorer to share with the community.

Once your project is successfully created, the system will redirect to the Project dashboard, where you will find details and an option to deploy your indexer to either the production or staging slot.

Image description

Step 5: Deploy your indexer to Production

In the previous step, we created the display behaviour of the project by configuring the basic details like name, description and so on; now, we must deploy a version of it before it becomes operational. Deploying a version triggers a new SubQuery indexing operation to start and sets up the required query service to begin accepting GraphQL API requests.

To deploy a version, select “Deploy your first version” on your project's dashboard.

Image description

A modal will appear with an option to fill in the Deployment CID. Paste in the CID you copied from Step 3.

Image description

If your CID is valid, the system will fetch your indexer's manifest file from IPFS. Once you confirm that everything checks out, click next to configure the Query Service.

Image description

The default options should be sufficient. However, you can learn more about these in the SubQuery documentation.

To configure the indexer service, we need to provide a custom network endpoint. A good point to note here is most public RPC providers will rate limit their public API endpoint which may slow down your SubQuery project. You can get a private endpoint without a rate limit from OnFinality or POKT.

Fill in your custom endpoint and click “Deploy” to kick off the deployment process.

Image description

If deployed successfully, you'll see the indexer start working and report back progress on indexing the current chain. This process may take time until it reaches 100%.

Image description

Step 6: Connect to your Project

Once the process is completed and SubQuery's nodes have indexed your data from the chain, you can now start making requests to your custom GraphQL Query endpoint displayed on the dashboard.

Image description

What's next?

Congratulations! If you followed along, you have learned how to deploy your indexer project to SubQuery’s production grade Managed Service. You can check out SubQuery documentation for tips that will be useful for running high performance SubQuery infrastructure and improving your indexing and query speed.

Top comments (4)

Collapse
 
sabrinaesaquino profile image
Sabrina

The best quickstart guide to Subquery. Thanks for sharing Yinka

Collapse
 
denitech profile image
Deni

Love the intro To SubQuery! Thanks :D

Collapse
 
danizeres profile image
Dani Passos

Great overview 🔥

Collapse
 
beapaz profile image
Bia Paz

this is awesome 🔥

thank you for the great content!