1. Create a New Project

... 2022-8-15 大约 3 分钟

# 1. Create a New Project

The goal of this quick start guide is to provide you with a complete development setup and guided steps to create your first SubQuery blockchain project. It is targeted towards experienced developers right through to those just beginning their blockchain journey.

This quick start guide should take around 10-15 minutes.

After completing this quick start guide, you will have a working SubQuery project that will run on a SubQuery node. You will be able to adapt the standard starter project and index transfers from your favourite blockchain network such as Polkadot, Avalanch, Cosmos, etc.

Let's start the process of creating your first SubQuery blockchain project.

# Prerequisites

Before you begin creating your first blockchain project with SubQuery, make sure you have installed the required supporting software applications. These are:

Now, you are all set to start with the first step, which is the installation of the SubQuery CLI.

# 1. 安装 SubQuery CLI

使用 NPM 在终端上全局安装 SubQuery CLI:

npm install -g @subql/cli

Note: We DO NOT encourage the use of yarn global for installing @subql/cli due to its poor dependency management. This may lead to multiple errors.

Take a look at all available commands and their use. Run the given below command in the CLI:

subql help

# 2. 初始化 Starter SubQuery 项目

Run the following command inside the directory you want to create a SubQuery project:

subql init

**For Cosmos Users**

Cosmos is not yet supported in SubQuery's CLI (subql). Hence, if you are using Cosmos, you must start with a Juno clone or fork this starter project (opens new window).

To initialise your project with Cosmos, refer to these 4 steps shown in this link. (opens new window). Once you complete these 4 steps, jump to the Make Changes to Your Project section. :::

You'll be asked certain questions as you proceed ahead:

  • Project name: A project name for your SubQuery project
  • Network family: The layer-1 blockchain network family that this SubQuery project will index. 使用箭头键从可用选项中选择。 For example, Polkadot, Avalanche, Cosmos, or any other supported network.
  • Network: The specific network that this SubQuery project will index. 使用箭头键从可用选项中选择。 For example, Polkadot, Avalanche, or any other supported network.
  • Template project: Select a SubQuery template project that will provide a starting point in the development. We suggest selecting the "subql-starter" project.
  • RPC endpoint: Provide an HTTPS URL to a running RPC endpoint, which will be used by default for this project. You can quickly access public endpoints for different networks, create your own private dedicated node using OnFinality (opens new window), or just use the default endpoint. 此 RPC 节点必须是归档节点 (具有完整链状态)。 We will use the default value for this guide. Based on the network you have chosen, the default value may be:
    • For Polkadot - "https://polkadot.api.onfinality.io"
    • For Avalanche - "https://avalanche.api.onfinality.io"
    • For Terra - “https://terra-columbus-5.beta.api.onfinality.io” and likewise for other networks.
  • Git repository: Provide a Git URL to a repo that this SubQuery project will be hosted in (when hosted in SubQuery Explorer) or accept the provided default.
  • Authors: Enter the owner of this SubQuery project here (e.g. your name!) or accept the provided default.
  • Description: Provide a short paragraph about your project that describes what data it contains and what users can do with it, or accept the provided default.
  • Version: Enter a custom version number or use the default (1.0.0)
  • License: Provide the software license for this project or accept the default (MIT)

Let’s look at an example:

$ subql init
Project name [subql-starter]: HelloWorld
? Select a network family Substrate
? Select a network Polkadot
? Select a template project subql-starter     Starter project for subquery
RPC endpoint: [wss://polkadot.api.onfinality.io/public-ws]:
Git repository [https://github.com/subquery/subql-starter]:
Fetching network genesis hash... done
Author [Ian He & Jay Ji]: Sean
Description [This project can be used as a starting po...]:
Version [1.0.0]:
License [MIT]:
Preparing project... done
HelloWorld is ready

After you complete the initialisation process, you will see a folder with your project name created inside the directory. Please note that the contents of this directory should be identical to what's listed in the Directory Structure.

Finally, run the following command to install the new project’s dependencies from within the new project's directory.

You have now initialised your first SubQuery project with just a few simple steps. Let’s now customise the standard template project for a specific blockchain of interest.

You may want to refer to the command line arguments used in SubQuery. It will help you understand the commands better.

# 3. Make Changes to Your Project

There are 3 important files that need to be modified. 您将主要处理下列文件:

  1. schema.graphql中的 GraphQL Schema
  2. project.yaml 中的项目清单
  3. src/mappings/ 目录中的映射函数

SubQuery supports various blockchain networks and provides you with a dedicated guide for each of them.

Pick up your preferred network and proceed ahead to make the modifications required, and move an inch closer to finishing your first ever project:





上次编辑于: 2022年8月15日 23:43