Getting Started with SubQuery Managed Service
geniusyinka
Posted on March 4, 2024
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:
- 99.9% Uptime Hosting: SubQuery is designed to provide reliable and consistent uptime for your applications.
- Dedicated Databases: For production applications, SubQuery offers an option to upgrade to a private dedicated database for your indexing needs.
- Advanced monitoring and analytics: SubQuery provides a detailed analytics panel to monitor the health of your applications.
- 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.
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.
Copy the token from the pop-up that appears.
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>
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
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
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”.
You'll be taken to the new project form. Here, you can fill in the project name, description, database type, and project visibility status.
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.
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.
A modal will appear with an option to fill in the Deployment CID
. Paste in the CID you copied from Step 3.
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.
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.
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%.
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.
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.
Posted on March 4, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 29, 2024