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
Refer to the official Graph CLI documentation for more details.
--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.).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.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
Edit the
docker-compose.yml file (below) and update environment.ethereum so it refers to the Virtual Environment RPC.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'
graph codegen
graph create --node http://localhost:8020 your-subgraph-name
graph deploy --node http://localhost:8020 --ipfs http://localhost:5001 your-subgraph-name
After deployment, access your subgraph through the URL below. Open this URL in your browser to access the subgraph and run queries: