graph-cliis a command line interface that helps you to quickly setup and manage your subgraphs.
Installing Graph CLI
Install with yarn:
yarn global add @graphprotocol/graph-cliInstall with npm:
npm install -g @graphprotocol/graph-cliUsage
Graph CLI provides several commands to help you on your subgraph developing journey:
-
init- Thegraph initcommand scaffolds a subgraph from a contract ABI downloaded from etherscan (or another explorer) or from a local file. It has a step-by-step interactive guide that will take you through the process of setting up your subgraph.$ graph init ✔ Protocol · ethereum ✔ Product for which to initialize · subgraph-studio ✔ Subgraph slug · Gravatar ✔ Directory to create the subgraph in · gravatar ✔ Ethereum network · mainnet ✔ Contract address · 0x2E645469f354BB4F5c8a05B3b30A929361cf77eC ✔ Fetching ABI from Etherscan ✔ Fetching Start Block ✔ Start Block · 6175244 ✔ Contract Name · Gravatar ✔ Index contract events as entities (Y/n) · false Generate subgraph Write subgraph to directory ✔ Create subgraph scaffold ✔ Initialize networks config ✔ Initialize subgraph repository ✔ Install dependencies with npm install ✔ Generate ABI and schema types with npm run codegen Add another contract? (y/n): Subgraph Gravatar created in gravatar Next steps: 1. Run `graph auth` to authenticate with your deploy key. 2. Type `cd gravatar` to enter the subgraph. 3. Run `npm run deploy` to deploy the subgraph. Make sure to visit the documentation on https://thegraph.com/docs/ for further information. -
add- Sometimes we want to add newdataSourcesto our subgraphs,graph addallows you to add new contracts to your existing subgraph. -
codegen-graph codegenwill generates the AssemblyScript bindings based on the data defined in the ABI,schema.graphqlandsubgraph.yamlfiles. -
build-graph buildcompiles the subgraph to WASM. You can use that command to check if the code you have written is correctly. -
auth- Usegraph authto authenticate with the studio using your deploy key or the hosted-service with your access token. -
deploy-graph deploywill compile and deploy the subgraph to the hosted-service or the subgraph studio, depending on your subgraph configuration. -
test-graph testwill execute the subgraph unit test using the matchstick testing library. More about subgraph unit testing can be found here
Run graph <command> —help to see usage information