This project holds a subgraph that is available for query on The Graph. Access to the hosted data is enabled via GraphQL.
This is the subgraph source code, which contains the subgraph manifest and the mappers code. The way The Graph is by using subgraph to index data. The service listens to the events emitted by the defined contracts in the manifest, and based on the coded configuration, it will handle the events via the mappers in the src/mapping.ts file. The file will contain a function for each event that the subgraph is configured to listen to.
The service will store the data that the mappers tell it to store, and it will make it available via GraphQL for querying purposes.
In order to update the current Subgraph, the following steps are to be taken:
-
Add your new schemas on the
schema.graphqlfile, this file updating this file requires at GraphQL basic knowledge about modeling data. -
Make sure you add the ABI in a json file in the
abisfolder. -
Update the
subgraph.yamlfile to add new data-sources (smart contracts) and their respective configurations. You can follow the current setup as a guide. In short, you want to add a new data-source under thedataSourcesarray, usingyamlsyntax. Remember to reference the ABI you created in the step before, as part of theyamlconfig in this file. -
After updating the schema and the subgraph config, you need to run
yarn codegenornpm run codegen. This will generate the AssemblyScript typings for all the schemas and will update thesrc/mapping.tsto reflect any new event handler on any of the declared contracts. -
In order to deploy your changes, just run
yarn build && yarn deploy. This will make your changes available in The Graph hosted service and the subgraph will sync against the network.
You can find a documentation on how to create a subgraph from scratch here.
The reference to AssemblyScript can be found here and the API support for AssemblyScript in The Graph mappers can be found here.
-
You can code your smart contracts in the
contractsfolder -
Add your contracts migrations on the
migrationsfile -
Run
truffle compileto generate the.jsonfile for your contracts, these files will contain the ABI as part of the content. -
Run
truffle migrate --network put-network-hereto make your contracts available in any network.
Reference to Truffle's documentation here.
-
Create subgraph related to this project here.
-
Update
package.jsonscripts to point to the correct subgraph by replacingorganization/tired-subgraphwith the correct subgraph name. -
Update the current
subgraph.yamlfile to add the correct contract address when we go live into prod.