Getting Started with SubQuery Managed Service
Published: 2024-03-04 19:46:01

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

[SubQuery](https://subquery.network/) 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](https://academy.subquery.network/run_publish/run.html).

### **Step 1: Create an account**

The first step is to create a Managed Service account. Go to [SubQuery Managed Service](https://managedservice.subquery.network/) to register or log in if you already have an account.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/giigiy852kj19xd5sxrz.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8i3y63n87mslqj2oca7a.png)

Copy the token from the pop-up that appears.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s1z8murnw9r3hfs0b8o3.png)

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

```bash
// 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:

```bash
// Publish it from your project's root directory
subql publish
```

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

```bash
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”.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t1w5clylqhx3oa7jksmy.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kmztfi273qxjwxglj4s1.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qzvwktbitm749vbv3px3.png)

### **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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/boz2199fkbfcy5la9prc.png)

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z6iuci8lo74zeioq7n9h.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9znnphd8kamrm8dryvbs.png)

The default options should be sufficient. However, you can learn more about these in the [SubQuery documentation](https://academy.subquery.network/run_publish/publish.html).

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](https://dillinger.io/link-to-onfinality-docs) or [POKT](https://dillinger.io/links-to-pokt-docs).

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c5pz8j794n2ryndoirir.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mvsiq3j6gsinke16880t.png)

### **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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1zq35o58peokfprf7gtb.png)

## **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](https://academy.subquery.network/run_publish/optimisation.html) and [improving your indexing and query speed](https://academy.subquery.network/build/optimisation.html).