This document explains how to initialize, create, and deploy your subgraph to the sandbox Subgraph Studio which can be published to hosted service once testing is done.
-
Prerequisite
- Connect Subgraph Sudio with wallet (eg: metamask)
- Create API key
-
Install Graph CLI with either npm or yarn
npm install -g @graphprotocol/graph-cli
yarn global add @graphprotocol/graph-cli
- Run below command to create new subgraph for existing smart contract. Below example creates the subgraph for uniswap smart contract.
graph init --protocol ethereum --network goerli --from-contract 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984 --contract-name UNI --studio --index-events subgraph_slug_name subgraph_directory
- Authenticate within CLI by providing Subgraph Studio API key
graph auth --studio <api_key>
- Go to subgraph directory
cd subgraph_directory
- Build the subgraph
graph codegen && graph build
- Deploy subgraph to Subgraph Studio
graph deploy --studio subgraph_slug_name
- You can access and use playground for the deployed subgraph at below url
https://thegraph.com/studio/subgraph/subgraph_slug_name/