Docs
Поиск⌘ K
  • Главная страница
  • О The Graph
  • Поддерживаемые сети
  • Protocol Contracts
  • Субграфы
    • Субпотоки
      • Token API
        • AI Suite
          • Индексирование
            • Ресурсы
              Субграфы > Разработка > Создание

              4 минуты

              Установка Graph CLI

              In order to use your Subgraph on The Graph’s decentralized network, you will need to create an API key in Subgraph Studio. It is recommended that you add signal to your Subgraph with at least 3,000 GRT to attract 2-3 Indexers. To learn more about signaling, check out curating.

              Обзор

              The Graph CLI⁠ is a command-line interface that facilitates developers’ commands for The Graph. It processes a Subgraph manifest and compiles the mappings to create the files you will need to deploy the Subgraph to Subgraph Studio and the network.

              Начало работы

              Установка Graph CLI

              The Graph CLI is written in TypeScript, and you must have node and either npm or yarn installed to use it. Check for the most recent⁠ CLI version.

              Выполните одну из следующих команд на своём локальном компьютере:

              Using npm⁠

              1npm install -g @graphprotocol/graph-cli@latest

              Using yarn⁠

              1yarn global add @graphprotocol/graph-cli

              The graph init command can be used to set up a new Subgraph project, either from an existing contract or from an example Subgraph. If you already have a smart contract deployed to your preferred network, you can bootstrap a new Subgraph from that contract to get started.

              Создайте субграф

              Из существующего контракта

              The following command creates a Subgraph that indexes all events of an existing contract:

              1graph init \2  --product subgraph-studio3  --from-contract <CONTRACT_ADDRESS> \4  [--network <ETHEREUM_NETWORK>] \5  [--abi <FILE>] \6  <SUBGRAPH_SLUG> [<DIRECTORY>]
              • Команда пытается получить ABI контракта из Etherscan.

                • Интерфейс командной строки The Graph использует общедоступную конечную точку RPC. Несмотря на то, что возможны периодические сбои, повторные попытки обычно решают эту проблему. Если сбои продолжаются, рассмотрите возможность использования локального ABI.
              • Если какой-либо из необязательных аргументов отсутствует, Вам будет предложено воспользоваться интерактивной формой.

              • The <SUBGRAPH_SLUG> is the ID of your Subgraph in Subgraph Studio. It can be found on your Subgraph details page.

              Из примера подграфа

              The following command initializes a new project from an example Subgraph:

              1graph init <SUBGRAPH_SLUG> --from-example=example-subgraph
              • The example Subgraph⁠ is based on the Gravity contract by Dani Grant, which manages user avatars and emits NewGravatar or UpdateGravatar events whenever avatars are created or updated.

              • The Subgraph handles these events by writing Gravatar entities to the Graph Node store and ensuring these are updated according to the events.

              Add New dataSources to an Existing Subgraph

              dataSources are key components of Subgraphs. They define the sources of data that the Subgraph indexes and processes. A dataSource specifies which smart contract to listen to, which events to process, and how to handle them.

              Recent versions of the Graph CLI supports adding new dataSources to an existing Subgraph through the graph add command:

              1graph add <address> [<subgraph-manifest default: "./subgraph.yaml">]23Options:45      --abi <path>              Path to the contract ABI (default: download from Etherscan)6      --contract-name           Name of the contract (default: Contract)7      --merge-entities          Whether to merge entities with the same name (default: false)8      --network-file <path>     Networks config file path (default: "./networks.json")

              Специфические особенности

              The graph add command will fetch the ABI from Etherscan (unless an ABI path is specified with the --abi option) and creates a new dataSource, similar to how the graph init command creates a dataSource --from-contract, updating the schema and mappings accordingly. This allows you to index implementation contracts from their proxy contracts.

              • The --merge-entities option identifies how the developer would like to handle entity and event name conflicts:

                • If true: the new dataSource should use existing eventHandlers & entities.

                • If false: a new entity & event handler should be created with ${dataSourceName}{EventName}.

              • The contract address will be written to the networks.json for the relevant network.

              Note: When using the interactive CLI, after successfully running graph init, you’ll be prompted to add a new dataSource.

              Получение ABIs

              Файл(ы) ABI должен(ы) соответствовать Вашему контракту (контрактам). Существует несколько способов получения файлов ABI:

              • Если Вы создаете свой собственный проект, у Вас, скорее всего, будет доступ к наиболее актуальным ABIS.
              • If you are building a Subgraph for a public project, you can download that project to your computer and get the ABI by using npx hardhat compile⁠ or using solc to compile.
              • You can also find the ABI on Etherscan⁠, but this isn’t always reliable, as the ABI that is uploaded there may be out of date. Make sure you have the right ABI, otherwise running your Subgraph will fail.
              ⁠Редактировать на GitHub⁠

              Starting Your SubgraphSubgraph Manifest
              На этой странице
              • Обзор
              • Начало работы
              • Установка Graph CLI
              • Создайте субграф
              • Из существующего контракта
              • Из примера подграфа
              • Add New dataSources to an Existing Subgraph
              • Получение ABIs
              The GraphСтатусТестовая сетьБрундовые ресурсыФорумБезопасностьПолитика конфиденциальностиУсловия обслуживания