Docs
Arama⌘ K
  • Ana sayfa
  • Graph Hakkında
  • Desteklenen Ağlar
  • Protocol Contracts
  • Subgraph'ler
    • Substream'ler
      • Token API
        • AI Suite
          • Endeksleme
            • Kaynaklar
              Subgraph'ler > Geliştirme > Dağıtma

              5 dakika

              Bir Subgraph'i Birden Fazla Ağda Dağıtma

              This page explains how to deploy a Subgraph to multiple networks. To deploy a Subgraph you need to first install the Graph CLI⁠. If you have not created a Subgraph already, see Creating a Subgraph.

              Deploying the Subgraph to multiple networks

              In some cases, you will want to deploy the same Subgraph to multiple networks without duplicating all of its code. The main challenge that comes with this is that the contract addresses on these networks are different.

              graph-cli Kullanarak

              Hem graph build (v0.29.0’dan itibaren) hem de graph deploy (v0.32.0’dan itibaren) komutları iki yeni seçeneği kabul eder:

              1Seçenekler:23      ...4      --network <name>          Ağ yapılandırmasını networks config dosyasını kullanarak yapmak için5      --network-file <path>     Ağ yapılandırma dosya yolu (varsayılan: "./networks.json")

              You can use the --network option to specify a network configuration from a json standard file (defaults to networks.json) to easily update your Subgraph during development.

              Not: Artık, init komutu, sağlanan bilgilere dayanarak otomatik olarak bir networks.json dosyası oluşturmaktadır. Daha sonra mevcut ağları güncelleyebilir veya yeni ağlar ekleyebilirsiniz.

              Eğer bir networks.json dosyanız yoksa, aşağıdaki yapı ile manuel olarak oluşturmanız gerekecek:

              1{2    "network1": { // ağ adı3        "dataSource1": { //veri kaynağı adı4            "address": "0xabc...", // sözleşme adresi (isteğe bağlı)5            "startBlock": 123456 // başlangıç bloku (isteğe bağlı)6        },7        "dataSource2": {8            "address": "0x123...",9            "startBlock": 12344410        }11    },12    "network2": {13        "dataSource1": {14            "address": "0x987...",15            "startBlock": 12316        },17        "dataSource2": {18            "address": "0xxyz..",19            "startBlock": 45620        }21    },22    ...23}

              Not: Yapılandırma dosyasında templates (şablonlar, eğer varsa) kısmını doldurmanıza gerek yoktur, yalnızca dataSources (veri kaynaklarını) belirtmelisiniz. Eğer subgraph.yaml dosyasında templates kısmı tanımlanmışsa, bunların ağı --network seçeneği ile belirtilen ağa otomatik olarak güncellenecektir.

              Now, let’s assume you want to be able to deploy your Subgraph to the mainnet and sepolia networks, and this is your subgraph.yaml:

              1# ...2dataSources:3  - kind: ethereum/contract4    name: Gravity5    network: mainnet6    source:7      address: '0x123...'8      abi: Gravity9    mapping:10      kind: ethereum/events

              Ağ yapılandırma dosyanız şu şekilde olmalıdır:

              1{2  "mainnet": {3    "Gravity": {4      "address": "0x123..."5    }6  },7  "sepolia": {8    "Gravity": {9      "address": "0xabc..."10    }11  }12}

              Şimdi aşağıdaki komutlardan birini çalıştırabilirsiniz:

              1# Varsayılan networks.json dosyasını kullanarak2yarn build --network sepolia34# Özel adlandırılmış bir dosya kullanarak5yarn build --network sepolia --network-file path/to/config

              The build command will update your subgraph.yaml with the sepolia configuration and then re-compile the Subgraph. Your subgraph.yaml file now should look like this:

              1# ...2dataSources:3  - kind: ethereum/contract4    name: Gravity5    network: sepolia6    source:7      address: '0xabc...'8      abi: Gravity9    mapping:10      kind: ethereum/events

              Artık yarn deploy komutunu çalıştırmaya hazırsınız.

              Not: Daha önce de belirtildiği gibi, graph-cli 0.32.0 sürümünden itibaren yarn deploy komutunu doğrudan --network seçeneğiyle çalıştırabilirsiniz:

              1# Varsayılan networks.json dosyasını kullanarak2yarn deploy --network sepolia34# Özel adlandırılmış bir dosya kullanarak5yarn deploy --network sepolia --network-file path/to/config

              subgraph.yaml şablonunu kullanarak:

              Daha eski graph-cli sürümlerini kullanarak kontrat adresleri gibi unsurları parametrize etmenin bir yolu, bunların bir kısmını Mustache⁠ veya Handlebar⁠ gibi bir şablonlama sistemiyle oluşturmaktır.

              To illustrate this approach, let’s assume a Subgraph should be deployed to mainnet and Sepolia using different contract addresses. You could then define two config files providing the addresses for each network:

              1{2  "network": "mainnet",3  "address": "0x123..."4}

              ve

              1{2  "network": "sepolia",3  "address": "0xabc..."4}

              Bununla birlikte, ağ adını ve adresleri manifesto içinde {{network}} ve {{address}} gibi değişken yer tutucularla değiştirir ve manifestoyu örneğin subgraph.template.yaml olarak yeniden adlandırırsınız:

              1# ...2dataSources:3  - kind: ethereum/contract4    name: Gravity5    network: mainnet6    network: {{network}}7    source:8      address: '0x2E645469f354BB4F5c8a05B3b30A929361cf77eC'9      address: '{{address}}'10      abi: Gravity11    mapping:12      kind: ethereum/events

              Her iki ağ için de bir manifesto oluşturmak amacıyla, package.json dosyasına mustache gereksinimiyle birlikte iki ek komut ekleyebilirsiniz:

              1{2  ...3  "scripts": {4    ...5    "prepare:mainnet": "mustache config/mainnet.json subgraph.template.yaml > subgraph.yaml",6    "prepare:sepolia": "mustache config/sepolia.json subgraph.template.yaml > subgraph.yaml"7  },8  "devDependencies": {9    ...10    "mustache": "^3.1.0"11  }12}

              To deploy this Subgraph for mainnet or Sepolia you would now simply run one of the two following commands:

              1# Mainnet:2yarn prepare:mainnet && yarn deploy34# Sepolia:5yarn prepare:sepolia && yarn deploy

              Bunun çalışan bir örneğini burada⁠ bulabilirsiniz.

              Not: Bu yaklaşım, sözleşme adresleri ve ağ adlarının ötesinde daha fazla değişiklik yapmanın, veya şablonlardan mapping ya da ABI’ler oluşturmanın gerekli olduğu, daha karmaşık durumlara da uygulanabilir.

              This will give you the chainHeadBlock which you can compare with the latestBlock on your Subgraph to check if it is running behind. synced informs if the Subgraph has ever caught up to the chain. health can currently take the values of healthy if no errors occurred, or failed if there was an error which halted the progress of the Subgraph. In this case, you can check the fatalError field for details on this error.

              Subgraph Studio Subgraph archive policy

              A Subgraph version in Studio is archived if and only if it meets the following criteria:

              • Sürüm ağa yayımlanmamıştır (veya yayım askıda kalmıştır)
              • Sürüm, 45 gün veya daha uzun bir süre önce oluşturulmuştur
              • The Subgraph hasn’t been queried in 30 days

              In addition, when a new version is deployed, if the Subgraph has not been published, then the N-2 version of the Subgraph is archived.

              Every Subgraph affected with this policy has an option to bring the version in question back.

              Checking Subgraph health

              If a Subgraph syncs successfully, that is a good sign that it will continue to run well forever. However, new triggers on the network might cause your Subgraph to hit an untested error condition or it may start to fall behind due to performance issues or issues with the node operators.

              Graph Node exposes a GraphQL endpoint which you can query to check the status of your Subgraph. On the hosted service, it is available at https://api.thegraph.com/index-node/graphql. On a local node, it is available on port 8030/graphql by default. The full schema for this endpoint can be found here⁠. Here is an example query that checks the status of the current version of a Subgraph:

              1{2  indexingStatusForCurrentVersion(subgraphName: "org/subgraph") {3    synced4    health5    fatalError {6      message7      block {8        number9        hash10      }11      handler12    }13    chains {14      chainHeadBlock {15        number16      }17      latestBlock {18        number19      }20    }21  }22}

              This will give you the chainHeadBlock which you can compare with the latestBlock on your Subgraph to check if it is running behind. synced informs if the Subgraph has ever caught up to the chain. health can currently take the values of healthy if no errors occurred, or failed if there was an error which halted the progress of the Subgraph. In this case, you can check the fatalError field for details on this error.

              ⁠GitHub'da Düzenle⁠

              Deploying Using Subgraph StudioPublishing to the Decentralized Network
              Bu sayfada
              • Deploying the Subgraph to multiple networks
              • graph-cli Kullanarak
              • subgraph.yaml şablonunu kullanarak:
              • Subgraph Studio Subgraph archive policy
              • Checking Subgraph health
              The GraphStatusTestnetBrand AssetsForumSecurityPrivacy PolicyTerms of Service