Developer FAQs
1. Can I delete my subgraph?
It is not possible to delete subgraphs once they are created.
2. Can I change my subgraph name?
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.
3. 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.
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.
5. Is it possible to deploy one subgraph with the same name for multiple networks?
You will need separate names for multiple networks. While you can't have different subgraphs under the same name, there are convenient ways of having a single codebase for multiple networks. Find more on this in our documentation: Redeploying a Subgraph
6. 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.
7. How do I make sure I'm using the latest version of graph-node for my local deployments?
You can run the following command:
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?
Take a look at Access to smart contract
state inside the section AssemblyScript API.
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
?
graph init
from graph-cli
with two contracts? Or should I manually add another datasource in subgraph.yaml
after running graph init
?Unfortunately, this is currently not possible. graph init
is intended as a basic starting point, from which you can then add more data sources manually.
10. I want to contribute or add a GitHub issue. Where can I find the open source repositories?
11. 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?
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, Kovan, Ropsten, local) from within event handlers?
Yes. You can do this by importing graph-ts
as per the example below:
14. Do you support block and call handlers on Rinkeby?
On Rinkeby we support block handlers, but without filter: call
. Call handlers are not supported for the time being.
15. 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.
16. 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
17. 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
18. 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:
19. What networks are supported by The Graph?
The graph-node supports any EVM-compatible JSON RPC API chain.
The Graph Network supports subgraphs indexing mainnet Ethereum:
mainnet
In the Hosted Service, the following networks are supported:
Ethereum mainnet
Kovan
Rinkeby
Ropsten
Goerli
PoA-Core
PoA-Sokol
xDAI
NEAR
NEAR testnet
Matic
Mumbai
Fantom
Binance Smart Chain
Clover
Avalanche
Fuji
Celo
Celo-Alfajores
Fuse
Moonbeam
Arbitrum One
Arbitrum Testnet (on Rinkeby)
Optimism
Optimism Testnet (on Kovan)
There is work in progress towards integrating other blockchains, you can read more in our repo: RFC-0003: Multi-Blockchain Support.
20. 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?
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?
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:
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.
24. Where do I go to find my current subgraph on the Hosted Service?
Head over to the Hosted Service in order to find subgraphs that you or others deployed to the Hosted Service. You can find it here.
25. Will the Hosted Service start charging query fees?
The Graph will never charge for the Hosted Service. The Graph is a decentralized protocol, and charging for a centralized service is not aligned with The Graph’s values. The Hosted Service was always a temporary step to help get to the decentralized network. Developers will have a sufficient amount of time to migrate to the decentralized network as they are comfortable.
26. When will the Hosted Service be shut down?
If and when there are plans to do this, the community will be notified well ahead of time with considerations made for any subgraphs built on the Hosted Service.
27. How do I upgrade a subgraph on mainnet?
If you’re a subgraph developer, you can upgrade a new version of your subgraph to the 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.
Last updated