Prerequisites
Ensure you have the following prerequisites installed on your system:- Node.js and npm
- Docker
- A Tenderly account
- A Virtual Environment RPC
- A smart contract deployed to Virtual Environment using Hardhat or Foundry
Set up The Graph
1
Install Graph CLI Globally
2
Install the Graph CLI globally on your system using npm:
3
npm install -g @graphprotocol/graph-cli
4
Refer to the official Graph CLI documentation for more details.
5
Set up The Graph project
6
Inside your project directory, initialize The Graph project.
7
Notes:
8
--abi to point to contrac ABI on your local system--contract-name and --from-contract with contract name and address, respectively--start-block--network so it references the network you based your Virtual Environment off of (e.g. mainnet, base, etc.).9
We recommend having
network match the original network’s name, without labeling it as virtual_. This enables effortless switching of RPCs when deploying to different staging and demoing environments.10
graph init your-subgraph-name subgraph-dir \
--protocol ethereum \
--studio \
--abi path/to/abi/ERC20Token.json \
--contract-name ERC20TokenFactory \
--from-contract 0x7F2Fa32C991fD2F8dF3EB23C394f550376e9b30d \
--start-block 0 \
--network mainnet
11
Graph Initialization documentation
12
Update
docker-compose.yml13
Edit the
docker-compose.yml file (below) and update environment.ethereum so it refers to the Virtual Environment RPC.14
version: '3'
services:
graph-node:
image: graphprotocol/graph-node
ports:
- '8020:8020'
- '8000:8000'
- '5001:5001'
environment:
postgres_host: postgres
postgres_user: graph-node
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: 'ipfs:5001'
ethereum: 'mainnet:https://virtual.mainnet.rpc.tenderly.co/d0a6...-40..2c-81..0f-a5..90'
15
Graph Docker documentation
16
Run Docker Compose locally
17
After setting up docker-compose config, run the following:
18
docker-compose up
19
Create and deploy your subgraph
20
Run the following commands, replacing
your-subgraph-name with the desired name for your subgraph.21
graph codegen
graph create --node http://localhost:8020 your-subgraph-name
graph deploy --node http://localhost:8020 --ipfs http://localhost:5001 your-subgraph-name
22
Graph Deployment documentation
23
Access the subgraph
24
After deployment, access your subgraph through the URL below. Open this URL in your browser to access the subgraph and run queries:
25
Deployed to http://localhost:8000/subgraphs/name/your-subgraph-name26
Graph Query documentation
27
Deploy to Cloud
28
For dapp staging, deploy The Graph node your cloud provider of choice, and connect your dapp UI/backend to that node for querying.