From b9a90ec81cab2fc77aff7acd361d7047430bfb4e Mon Sep 17 00:00:00 2001 From: Michael Macaulay <56690114+MichaelMacaulay@users.noreply.github.com> Date: Fri, 13 Sep 2024 16:44:52 -0400 Subject: [PATCH 1/4] Updates --- .../pages/en/developing/developer-faqs.mdx | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/website/pages/en/developing/developer-faqs.mdx b/website/pages/en/developing/developer-faqs.mdx index 8c4474270af1..e8567472736d 100644 --- a/website/pages/en/developing/developer-faqs.mdx +++ b/website/pages/en/developing/developer-faqs.mdx @@ -14,23 +14,19 @@ It is not possible to delete subgraphs once they are created. No. Once a subgraph is created, the name cannot be changed. Make sure to think of this carefully before you create your subgraph so it is easily searchable and identifiable by other dapps. -## 4. Can I change the GitHub account associated with my subgraph? - -No. Once a subgraph is created, the associated GitHub account cannot be changed. Make sure to think of this carefully before you create your subgraph. - -## 5. Am I still able to create a subgraph if my smart contracts don't have events? +## 4. Am I still able to create a subgraph if my smart contracts don't have events? It is highly recommended that you structure your smart contracts to have events associated with data you are interested in querying. Event handlers in the subgraph are triggered by contract events and are by far the fastest way to retrieve useful data. -If the contracts you are working with do not contain events, your subgraph can use call and block handlers to trigger indexing. Although this is not recommended, as performance will be significantly slower. +If the contracts you are working with do not contain events, your subgraph can use call and block handlers to trigger indexing, but this is not recommended as performance will be significantly slower. -## 6. How are templates different from data sources? +## 5. How are templates different from data sources? Templates allow you to create data sources on the fly, while your subgraph is indexing. It might be the case that your contract will spawn new contracts as people interact with it, and since you know the shape of those contracts (ABI, events, etc) upfront you can define how you want to index them in a template and when they are spawned your subgraph will create a dynamic data source by supplying the contract address. Check out the "Instantiating a data source template" section on: [Data Source Templates](/developing/creating-a-subgraph#data-source-templates). -## 7. How do I make sure I'm using the latest version of graph-node for my local deployments? +## 6. How do I make sure I'm using the latest version of graph-node for my local deployments? You can run the following command: @@ -38,32 +34,34 @@ You can run the following command: docker pull graphprotocol/graph-node:latest ``` -**NOTE:** docker / docker-compose will always use whatever graph-node version was pulled the first time you ran it, so it is important to do this to make sure you are up to date with the latest version of graph-node. +>Note: docker / docker-compose will always use whatever graph-node version was pulled the first time you ran it, so it is important to do this to make sure you are up to date with the latest version of graph-node. -## 8. How do I call a contract function or access a public state variable from my subgraph mappings? +## 7. How do I call a contract function or access a public state variable from my subgraph mappings? Take a look at `Access to smart contract` state inside the section [AssemblyScript API](/developing/graph-ts/api/#access-to-smart-contract-state). -## 9. Is it possible to set up a subgraph using `graph init` from `graph-cli` with two contracts? Or should I manually add another datasource in `subgraph.yaml` after running `graph init`? +## 8. Is it possible to set up a subgraph using `graph init` from `graph-cli` with two contracts? Or should I manually add another datasource in `subgraph.yaml` after running `graph init`? -Yes. On `graph init` command itself you can add multiple datasources by entering contracts one after the other. You can also use `graph add` command to add new datasource. +Yes. On `graph init` command itself you can add multiple datasources by entering contracts one after the other. -## 10. I want to contribute or add a GitHub issue. Where can I find the open source repositories? +You can also use `graph add` command to add new datasource. + +## 9. I want to contribute or add a GitHub issue. Where can I find the open source repositories? - [graph-node](https://github.com/graphprotocol/graph-node) - [graph-tooling](https://github.com/graphprotocol/graph-tooling) - [graph-docs](https://github.com/graphprotocol/docs) - [graph-client](https://github.com/graphprotocol/graph-client) -## 11. What is the recommended way to build "autogenerated" ids for an entity when handling events? +## 10. What is the recommended way to build "autogenerated" ids for an entity when handling events? If only one entity is created during the event and if there's nothing better available, then the transaction hash + log index would be unique. You can obfuscate these by converting that to Bytes and then piping it through `crypto.keccak256` but this won't make it more unique. -## 12. When listening to multiple contracts, is it possible to select the contract order to listen to events? +## 11. When listening to multiple contracts, is it possible to select the contract order to listen to events? Within a subgraph, the events are always processed in the order they appear in the blocks, regardless of whether that is across multiple contracts or not. -## 13. Is it possible to differentiate between networks (mainnet, Sepolia, local) from within event handlers? +## 12. Is it possible to differentiate between networks (mainnet, Sepolia, local) from within event handlers? Yes. You can do this by importing `graph-ts` as per the example below: @@ -74,23 +72,25 @@ dataSource.network() dataSource.address() ``` -## 14. Do you support block and call handlers on Sepolia? +## 13. Do you support block and call handlers on Sepolia? Yes. Sepolia supports block handlers, call handlers and event handlers. It should be noted that event handlers are far more performant than the other two handlers, and they are supported on every EVM-compatible network. -## 15. Can I import ethers.js or other JS libraries into my subgraph mappings? +## 14. Can I import ethers.js or other JS libraries into my subgraph mappings? + +Not currently, as mappings are written in AssemblyScript. -Not currently, as mappings are written in AssemblyScript. One possible alternative solution to this is to store raw data in entities and perform logic that requires JS libraries on the client. +One possible alternative solution to this is to store raw data in entities and perform logic that requires JS libraries on the client. -## 16. Is it possible to specify what block to start indexing on? +## 15. Is it possible to specify what block to start indexing on? Yes. `dataSources.source.startBlock` in the `subgraph.yaml` file specifies the number of the block that the data source starts indexing from. In most cases, we suggest using the block in which the contract was created: [Start blocks](/developing/creating-a-subgraph#start-blocks) -## 17. Are there some tips to increase the performance of indexing? My subgraph is taking a very long time to sync +## 16. Are there some tips to increase the performance of indexing? My subgraph is taking a very long time to sync Yes, you should take a look at the optional start block feature to start indexing from the block that the contract was deployed: [Start blocks](/developing/creating-a-subgraph#start-blocks) -## 18. Is there a way to query the subgraph directly to determine the latest block number it has indexed? +## 17. Is there a way to query the subgraph directly to determine the latest block number it has indexed? Yes! Try the following command, substituting "organization/subgraphName" with the organization under it is published and the name of your subgraph: @@ -98,19 +98,19 @@ Yes! Try the following command, substituting "organization/subgraphName" with th curl -X POST -d '{ "query": "{indexingStatusForCurrentVersion(subgraphName: \"organization/subgraphName\") { chains { latestBlock { hash number }}}}"}' https://api.thegraph.com/index-node/graphql ``` -## 19. What networks are supported by The Graph? +## 18. What networks are supported by The Graph? You can find the list of the supported networks [here](/developing/supported-networks). -## 20. Is it possible to duplicate a subgraph to another account or endpoint without redeploying? +## 19. Is it possible to duplicate a subgraph to another account or endpoint without redeploying? You have to redeploy the subgraph, but if the subgraph ID (IPFS hash) doesn't change, it won't have to sync from the beginning. -## 21. Is this possible to use Apollo Federation on top of graph-node? +## 20. Is this possible to use Apollo Federation on top of graph-node? Federation is not supported yet, although we do want to support it in the future. At the moment, something you can do is use schema stitching, either on the client or via a proxy service. -## 22. Is there a limit to how many objects The Graph can return per query? +## 21. Is there a limit to how many objects The Graph can return per query? By default, query responses are limited to 100 items per collection. If you want to receive more, you can go up to 1000 items per collection and beyond that, you can paginate with: @@ -118,15 +118,15 @@ By default, query responses are limited to 100 items per collection. If you want someCollection(first: 1000, skip: ) { ... } ``` -## 23. If my dapp frontend uses The Graph for querying, do I need to write my query key into the frontend directly? What if we pay query fees for users – will malicious users cause our query fees to be very high? +## 22. If my dapp frontend uses The Graph for querying, do I need to write my query key into the frontend directly? What if we pay query fees for users – will malicious users cause our query fees to be very high? Currently, the recommended approach for a dapp is to add the key to the frontend and expose it to end users. That said, you can limit that key to a hostname, like _yourdapp.io_ and subgraph. The gateway is currently being run by Edge & Node. Part of the responsibility of a gateway is to monitor for abusive behavior and block traffic from malicious clients. -## 24. How do I update a subgraph on mainnet? +## 23. How do I update a subgraph on mainnet? -If you’re a subgraph developer, you can deploy a new version of your subgraph to Subgraph Studio using the CLI. It’ll be private at that point, but if you’re happy with it, you can publish to the decentralized Graph Explorer. This will create a new version of your subgraph that Curators can start signaling on. +You can deploy a new version of your subgraph to Subgraph Studio using the CLI. It’ll be private at that point, but if you’re happy with it, you can publish to Graph Explorer. This will create a new version of your subgraph that Curators can start signaling on. -## 25. In what order are the event, block, and call handlers triggered for a data source? +## 24. In what order are the event, block, and call handlers triggered for a data source? Event and call handlers are first ordered by transaction index within the block. Event and call handlers within the same transaction are ordered using a convention: event handlers first then call handlers, each type respecting the order they are defined in the manifest. Block handlers are run after event and call handlers, in the order they are defined in the manifest. Also these ordering rules are subject to change. From 678e707a5b91df424e13dc52fdc4a2f218b9973d Mon Sep 17 00:00:00 2001 From: Idalith Bustos Date: Fri, 13 Sep 2024 18:06:11 -0700 Subject: [PATCH 2/4] organized questions --- .../pages/en/developing/developer-faqs.mdx | 128 ++++++++++-------- 1 file changed, 71 insertions(+), 57 deletions(-) diff --git a/website/pages/en/developing/developer-faqs.mdx b/website/pages/en/developing/developer-faqs.mdx index e8567472736d..193697cdecb1 100644 --- a/website/pages/en/developing/developer-faqs.mdx +++ b/website/pages/en/developing/developer-faqs.mdx @@ -2,66 +2,93 @@ title: Developer FAQs --- -## 1. What is a subgraph? +This page summarizes some of the common questions for developers building on The Graph. -A subgraph is a custom API built on blockchain data. Subgraphs are queried using the GraphQL query language and are deployed to a Graph Node using the Graph CLI. Once deployed and published to The Graph's decentralized network, Indexers process subgraphs and make them available to be queried by subgraph consumers. +## Subgraph Related -## 2. Can I delete my subgraph? +### 1. What is a subgraph? -It is not possible to delete subgraphs once they are created. +A subgraph is a custom API built on blockchain data. Subgraphs are queried using the GraphQL query language and are deployed to a Graph Node using The Graph CLI. Once deployed and published to The Graph's decentralized network, Indexers process subgraphs and make them available for subgraph consumers to query them. -## 3. Can I change my subgraph name? +### 2. What is the first step to create a subgraph? -No. Once a subgraph is created, the name cannot be changed. Make sure to think of this carefully before you create your subgraph so it is easily searchable and identifiable by other dapps. +To successfully create a subgraph and publish it on the decentralized network, you will need to install The Graph CLI. Review our [Creating a Subgraph](/developing/creating-a-subgraph/) page for detailed instructions. -## 4. Am I still able to create a subgraph if my smart contracts don't have events? +### 3. Can I still create a subgraph if my smart contracts don't have events? It is highly recommended that you structure your smart contracts to have events associated with data you are interested in querying. Event handlers in the subgraph are triggered by contract events and are by far the fastest way to retrieve useful data. -If the contracts you are working with do not contain events, your subgraph can use call and block handlers to trigger indexing, but this is not recommended as performance will be significantly slower. +If the contracts you work with do not contain events, your subgraph can use call and block handlers to trigger indexing. However, this is not recommended, as performance will be significantly slower. -## 5. How are templates different from data sources? +### 4. Can I change the GitHub account associated with my subgraph? -Templates allow you to create data sources on the fly, while your subgraph is indexing. It might be the case that your contract will spawn new contracts as people interact with it, and since you know the shape of those contracts (ABI, events, etc) upfront you can define how you want to index them in a template and when they are spawned your subgraph will create a dynamic data source by supplying the contract address. +No. Once a subgraph is created, the associated GitHub account cannot be changed. Please make sure to carefully consider this before creating your subgraph. -Check out the "Instantiating a data source template" section on: [Data Source Templates](/developing/creating-a-subgraph#data-source-templates). - -## 6. How do I make sure I'm using the latest version of graph-node for my local deployments? +### 5. How do I update a subgraph on mainnet? -You can run the following command: +You can deploy a new version of your subgraph to Subgraph Studio using the CLI. This action maintains your subgraph private, but once you’re happy with it, you can publish to Graph Explorer. This will create a new version of your subgraph that Curators can start signaling on. -```sh -docker pull graphprotocol/graph-node:latest -``` +### 6. When listening to multiple contracts, is it possible to select the contract order to listen to events? ->Note: docker / docker-compose will always use whatever graph-node version was pulled the first time you ran it, so it is important to do this to make sure you are up to date with the latest version of graph-node. +Within a subgraph, the events are always processed in the order they appear in the blocks, regardless of whether that is across multiple contracts or not. -## 7. How do I call a contract function or access a public state variable from my subgraph mappings? +### 7. How do I call a contract function or access a public state variable from my subgraph mappings? Take a look at `Access to smart contract` state inside the section [AssemblyScript API](/developing/graph-ts/api/#access-to-smart-contract-state). -## 8. Is it possible to set up a subgraph using `graph init` from `graph-cli` with two contracts? Or should I manually add another datasource in `subgraph.yaml` after running `graph init`? +### 8. Can I import ethers.js or other JS libraries into my subgraph mappings? + +Not currently, as mappings are written in AssemblyScript. + +One possible alternative solution to this is to store raw data in entities and perform logic that requires JS libraries on the client. + +### 9. Is it possible to duplicate a subgraph to another account or endpoint without redeploying? + +You have to redeploy the subgraph, but if the subgraph ID (IPFS hash) doesn't change, it won't have to sync from the beginning. + +### 10. How are templates different from data sources? + +Templates allow you to create data sources on the quickly, while your subgraph is indexing. Your contract might spawn new contracts as people interact with it. Since you know the shape of those contracts (ABI, events, etc.) upfront, you can define how you want to index them in a template. When they are spawned, your subgraph will create a dynamic data source by supplying the contract address. + +Check out the "Instantiating a data source template" section on: [Data Source Templates](/developing/creating-a-subgraph#data-source-templates). + +### 11. Is it possible to set up a subgraph using `graph init` from `graph-cli` with two contracts? Or should I manually add another datasource in `subgraph.yaml` after running `graph init`? Yes. On `graph init` command itself you can add multiple datasources by entering contracts one after the other. You can also use `graph add` command to add new datasource. -## 9. I want to contribute or add a GitHub issue. Where can I find the open source repositories? +### 12. In what order are the event, block, and call handlers triggered for a data source? -- [graph-node](https://github.com/graphprotocol/graph-node) -- [graph-tooling](https://github.com/graphprotocol/graph-tooling) -- [graph-docs](https://github.com/graphprotocol/docs) -- [graph-client](https://github.com/graphprotocol/graph-client) +Event and call handlers are first ordered by transaction index within the block. Event and call handlers within the same transaction are ordered using a convention: event handlers first then call handlers, each type respecting the order they are defined in the manifest. Block handlers are run after event and call handlers, in the order they are defined in the manifest. Also these ordering rules are subject to change. + +When new dynamic data source are created, the handlers defined for dynamic data sources will only start processing after all existing data source handlers are processed, and will repeat in the same sequence whenever triggered. -## 10. What is the recommended way to build "autogenerated" ids for an entity when handling events? +### 13. How do I make sure I'm using the latest version of graph-node for my local deployments? + +You can run the following command: + +```sh +docker pull graphprotocol/graph-node:latest +``` + +> Note: docker / docker-compose will always use whatever graph-node version was pulled the first time you ran it, so it is important to do this to make sure you are up to date with the latest version of graph-node. + +### 14. What is the recommended way to build "autogenerated" ids for an entity when handling events? If only one entity is created during the event and if there's nothing better available, then the transaction hash + log index would be unique. You can obfuscate these by converting that to Bytes and then piping it through `crypto.keccak256` but this won't make it more unique. -## 11. When listening to multiple contracts, is it possible to select the contract order to listen to events? +### 15. Can I delete my subgraph? -Within a subgraph, the events are always processed in the order they appear in the blocks, regardless of whether that is across multiple contracts or not. +It is not possible to delete subgraphs once they are created. However, you can [transfer and deprecate your subgraph](/managing/transfer-and-deprecate-a-subgraph/) + +## Network Related -## 12. Is it possible to differentiate between networks (mainnet, Sepolia, local) from within event handlers? +### 16. What networks are supported by The Graph? + +You can find the list of the supported networks [here](/developing/supported-networks). + +### 17. Is it possible to differentiate between networks (mainnet, Sepolia, local) from within event handlers? Yes. You can do this by importing `graph-ts` as per the example below: @@ -72,25 +99,21 @@ dataSource.network() dataSource.address() ``` -## 13. Do you support block and call handlers on Sepolia? +### 18. Do you support block and call handlers on Sepolia? Yes. Sepolia supports block handlers, call handlers and event handlers. It should be noted that event handlers are far more performant than the other two handlers, and they are supported on every EVM-compatible network. -## 14. Can I import ethers.js or other JS libraries into my subgraph mappings? - -Not currently, as mappings are written in AssemblyScript. +## Indexing & Querying Related -One possible alternative solution to this is to store raw data in entities and perform logic that requires JS libraries on the client. - -## 15. Is it possible to specify what block to start indexing on? +### 19. Is it possible to specify what block to start indexing on? Yes. `dataSources.source.startBlock` in the `subgraph.yaml` file specifies the number of the block that the data source starts indexing from. In most cases, we suggest using the block in which the contract was created: [Start blocks](/developing/creating-a-subgraph#start-blocks) -## 16. Are there some tips to increase the performance of indexing? My subgraph is taking a very long time to sync +### 20. Are there some tips to increase the performance of indexing? My subgraph is taking a very long time to sync Yes, you should take a look at the optional start block feature to start indexing from the block that the contract was deployed: [Start blocks](/developing/creating-a-subgraph#start-blocks) -## 17. Is there a way to query the subgraph directly to determine the latest block number it has indexed? +### 21. Is there a way to query the subgraph directly to determine the latest block number it has indexed? Yes! Try the following command, substituting "organization/subgraphName" with the organization under it is published and the name of your subgraph: @@ -98,19 +121,7 @@ Yes! Try the following command, substituting "organization/subgraphName" with th curl -X POST -d '{ "query": "{indexingStatusForCurrentVersion(subgraphName: \"organization/subgraphName\") { chains { latestBlock { hash number }}}}"}' https://api.thegraph.com/index-node/graphql ``` -## 18. What networks are supported by The Graph? - -You can find the list of the supported networks [here](/developing/supported-networks). - -## 19. Is it possible to duplicate a subgraph to another account or endpoint without redeploying? - -You have to redeploy the subgraph, but if the subgraph ID (IPFS hash) doesn't change, it won't have to sync from the beginning. - -## 20. Is this possible to use Apollo Federation on top of graph-node? - -Federation is not supported yet, although we do want to support it in the future. At the moment, something you can do is use schema stitching, either on the client or via a proxy service. - -## 21. Is there a limit to how many objects The Graph can return per query? +### 22. Is there a limit to how many objects The Graph can return per query? By default, query responses are limited to 100 items per collection. If you want to receive more, you can go up to 1000 items per collection and beyond that, you can paginate with: @@ -118,16 +129,19 @@ By default, query responses are limited to 100 items per collection. If you want someCollection(first: 1000, skip: ) { ... } ``` -## 22. If my dapp frontend uses The Graph for querying, do I need to write my query key into the frontend directly? What if we pay query fees for users – will malicious users cause our query fees to be very high? +### 23. If my dapp frontend uses The Graph for querying, do I need to write my query key into the frontend directly? What if we pay query fees for users – will malicious users cause our query fees to be very high? Currently, the recommended approach for a dapp is to add the key to the frontend and expose it to end users. That said, you can limit that key to a hostname, like _yourdapp.io_ and subgraph. The gateway is currently being run by Edge & Node. Part of the responsibility of a gateway is to monitor for abusive behavior and block traffic from malicious clients. -## 23. How do I update a subgraph on mainnet? +Miscellaneous -You can deploy a new version of your subgraph to Subgraph Studio using the CLI. It’ll be private at that point, but if you’re happy with it, you can publish to Graph Explorer. This will create a new version of your subgraph that Curators can start signaling on. +### 24. Is this possible to use Apollo Federation on top of graph-node? -## 24. In what order are the event, block, and call handlers triggered for a data source? +Federation is not supported yet, although we do want to support it in the future. At the moment, something you can do is use schema stitching, either on the client or via a proxy service. -Event and call handlers are first ordered by transaction index within the block. Event and call handlers within the same transaction are ordered using a convention: event handlers first then call handlers, each type respecting the order they are defined in the manifest. Block handlers are run after event and call handlers, in the order they are defined in the manifest. Also these ordering rules are subject to change. +### 25. I want to contribute or add a GitHub issue. Where can I find the open source repositories? -When new dynamic data source are created, the handlers defined for dynamic data sources will only start processing after all existing data source handlers are processed, and will repeat in the same sequence whenever triggered. +- [graph-node](https://github.com/graphprotocol/graph-node) +- [graph-tooling](https://github.com/graphprotocol/graph-tooling) +- [graph-docs](https://github.com/graphprotocol/docs) +- [graph-client](https://github.com/graphprotocol/graph-client) From 671a8ac361fa6a1899eaeb389ac1c78f6b6fb06b Mon Sep 17 00:00:00 2001 From: Idalith Bustos Date: Mon, 16 Sep 2024 11:09:11 -0700 Subject: [PATCH 3/4] tiny edit --- website/pages/en/developing/developer-faqs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/pages/en/developing/developer-faqs.mdx b/website/pages/en/developing/developer-faqs.mdx index 193697cdecb1..e2a7de927538 100644 --- a/website/pages/en/developing/developer-faqs.mdx +++ b/website/pages/en/developing/developer-faqs.mdx @@ -12,7 +12,7 @@ A subgraph is a custom API built on blockchain data. Subgraphs are queried using ### 2. What is the first step to create a subgraph? -To successfully create a subgraph and publish it on the decentralized network, you will need to install The Graph CLI. Review our [Creating a Subgraph](/developing/creating-a-subgraph/) page for detailed instructions. +To successfully create a subgraph, you will need to install The Graph CLI. Review the [Quick Start](/quick-start/) to get started. For detailed information, see [Creating a Subgraph](/developing/creating-a-subgraph/). ### 3. Can I still create a subgraph if my smart contracts don't have events? From 484b8d0cf4ce189e846b4292db7af0291f2c5b18 Mon Sep 17 00:00:00 2001 From: Idalith Bustos Date: Mon, 16 Sep 2024 13:12:59 -0700 Subject: [PATCH 4/4] Edits --- .../pages/en/developing/developer-faqs.mdx | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/website/pages/en/developing/developer-faqs.mdx b/website/pages/en/developing/developer-faqs.mdx index e2a7de927538..c8906615c081 100644 --- a/website/pages/en/developing/developer-faqs.mdx +++ b/website/pages/en/developing/developer-faqs.mdx @@ -2,13 +2,13 @@ title: Developer FAQs --- -This page summarizes some of the common questions for developers building on The Graph. +This page summarizes some of the most common questions for developers building on The Graph. ## Subgraph Related ### 1. What is a subgraph? -A subgraph is a custom API built on blockchain data. Subgraphs are queried using the GraphQL query language and are deployed to a Graph Node using The Graph CLI. Once deployed and published to The Graph's decentralized network, Indexers process subgraphs and make them available for subgraph consumers to query them. +A subgraph is a custom API built on blockchain data. Subgraphs are queried using the GraphQL query language and are deployed to a Graph Node using The Graph CLI. Once deployed and published to The Graph's decentralized network, Indexers process subgraphs and make them available for subgraph consumers to query. ### 2. What is the first step to create a subgraph? @@ -16,7 +16,7 @@ To successfully create a subgraph, you will need to install The Graph CLI. Revie ### 3. Can I still create a subgraph if my smart contracts don't have events? -It is highly recommended that you structure your smart contracts to have events associated with data you are interested in querying. Event handlers in the subgraph are triggered by contract events and are by far the fastest way to retrieve useful data. +It is highly recommended that you structure your smart contracts to have events associated with data you are interested in querying. Event handlers in the subgraph are triggered by contract events and are the fastest way to retrieve useful data. If the contracts you work with do not contain events, your subgraph can use call and block handlers to trigger indexing. However, this is not recommended, as performance will be significantly slower. @@ -28,35 +28,35 @@ No. Once a subgraph is created, the associated GitHub account cannot be changed. You can deploy a new version of your subgraph to Subgraph Studio using the CLI. This action maintains your subgraph private, but once you’re happy with it, you can publish to Graph Explorer. This will create a new version of your subgraph that Curators can start signaling on. -### 6. When listening to multiple contracts, is it possible to select the contract order to listen to events? +### 6. Is it possible to duplicate a subgraph to another account or endpoint without redeploying? -Within a subgraph, the events are always processed in the order they appear in the blocks, regardless of whether that is across multiple contracts or not. +You have to redeploy the subgraph, but if the subgraph ID (IPFS hash) doesn't change, it won't have to sync from the beginning. ### 7. How do I call a contract function or access a public state variable from my subgraph mappings? Take a look at `Access to smart contract` state inside the section [AssemblyScript API](/developing/graph-ts/api/#access-to-smart-contract-state). -### 8. Can I import ethers.js or other JS libraries into my subgraph mappings? +### 8. Can I import `ethers.js` or other JS libraries into my subgraph mappings? Not currently, as mappings are written in AssemblyScript. One possible alternative solution to this is to store raw data in entities and perform logic that requires JS libraries on the client. -### 9. Is it possible to duplicate a subgraph to another account or endpoint without redeploying? +### 9. When listening to multiple contracts, is it possible to select the contract order to listen to events? -You have to redeploy the subgraph, but if the subgraph ID (IPFS hash) doesn't change, it won't have to sync from the beginning. +Within a subgraph, the events are always processed in the order they appear in the blocks, regardless of whether that is across multiple contracts or not. ### 10. How are templates different from data sources? -Templates allow you to create data sources on the quickly, while your subgraph is indexing. Your contract might spawn new contracts as people interact with it. Since you know the shape of those contracts (ABI, events, etc.) upfront, you can define how you want to index them in a template. When they are spawned, your subgraph will create a dynamic data source by supplying the contract address. +Templates allow you to create data sources quickly, while your subgraph is indexing. Your contract might spawn new contracts as people interact with it. Since you know the shape of those contracts (ABI, events, etc.) upfront, you can define how you want to index them in a template. When they are spawned, your subgraph will create a dynamic data source by supplying the contract address. Check out the "Instantiating a data source template" section on: [Data Source Templates](/developing/creating-a-subgraph#data-source-templates). -### 11. Is it possible to set up a subgraph using `graph init` from `graph-cli` with two contracts? Or should I manually add another datasource in `subgraph.yaml` after running `graph init`? +### 11. Is it possible to set up a subgraph using `graph init` from `graph-cli` with two contracts? Or should I manually add another dataSource in `subgraph.yaml` after running `graph init`? -Yes. On `graph init` command itself you can add multiple datasources by entering contracts one after the other. +Yes. On `graph init` command itself you can add multiple dataSources by entering contracts one after the other. -You can also use `graph add` command to add new datasource. +You can also use `graph add` command to add a new dataSource. ### 12. In what order are the event, block, and call handlers triggered for a data source? @@ -72,7 +72,7 @@ You can run the following command: docker pull graphprotocol/graph-node:latest ``` -> Note: docker / docker-compose will always use whatever graph-node version was pulled the first time you ran it, so it is important to do this to make sure you are up to date with the latest version of graph-node. +> Note: docker / docker-compose will always use whatever graph-node version was pulled the first time you ran it, so make sure you're up to date with the latest version of graph-node. ### 14. What is the recommended way to build "autogenerated" ids for an entity when handling events? @@ -80,7 +80,7 @@ If only one entity is created during the event and if there's nothing better ava ### 15. Can I delete my subgraph? -It is not possible to delete subgraphs once they are created. However, you can [transfer and deprecate your subgraph](/managing/transfer-and-deprecate-a-subgraph/) +It is not possible to delete subgraphs once they are created. However, you can [transfer and deprecate your subgraph](/managing/transfer-and-deprecate-a-subgraph/). ## Network Related @@ -88,7 +88,7 @@ It is not possible to delete subgraphs once they are created. However, you can [ You can find the list of the supported networks [here](/developing/supported-networks). -### 17. Is it possible to differentiate between networks (mainnet, Sepolia, local) from within event handlers? +### 17. Is it possible to differentiate between networks (mainnet, Sepolia, local) within event handlers? Yes. You can do this by importing `graph-ts` as per the example below: @@ -107,11 +107,11 @@ Yes. Sepolia supports block handlers, call handlers and event handlers. It shoul ### 19. Is it possible to specify what block to start indexing on? -Yes. `dataSources.source.startBlock` in the `subgraph.yaml` file specifies the number of the block that the data source starts indexing from. In most cases, we suggest using the block in which the contract was created: [Start blocks](/developing/creating-a-subgraph#start-blocks) +Yes. `dataSources.source.startBlock` in the `subgraph.yaml` file specifies the number of the block that the dataSource starts indexing from. In most cases, we suggest using the block where the contract was created: [Start blocks](/developing/creating-a-subgraph#start-blocks) -### 20. Are there some tips to increase the performance of indexing? My subgraph is taking a very long time to sync +### 20. What are some tips to increase the performance of indexing? My subgraph is taking a very long time to sync -Yes, you should take a look at the optional start block feature to start indexing from the block that the contract was deployed: [Start blocks](/developing/creating-a-subgraph#start-blocks) +Yes, you should take a look at the optional start block feature to start indexing from the block where the contract was deployed: [Start blocks](/developing/creating-a-subgraph#start-blocks) ### 21. Is there a way to query the subgraph directly to determine the latest block number it has indexed? @@ -133,11 +133,11 @@ someCollection(first: 1000, skip: ) { ... } Currently, the recommended approach for a dapp is to add the key to the frontend and expose it to end users. That said, you can limit that key to a hostname, like _yourdapp.io_ and subgraph. The gateway is currently being run by Edge & Node. Part of the responsibility of a gateway is to monitor for abusive behavior and block traffic from malicious clients. -Miscellaneous +## Miscellaneous -### 24. Is this possible to use Apollo Federation on top of graph-node? +### 24. Is it possible to use Apollo Federation on top of graph-node? -Federation is not supported yet, although we do want to support it in the future. At the moment, something you can do is use schema stitching, either on the client or via a proxy service. +Federation is not supported yet. At the moment, you can use schema stitching, either on the client or via a proxy service. ### 25. I want to contribute or add a GitHub issue. Where can I find the open source repositories?