This Subgraph is indexing the SSVNetwork smart contract through the Events emitted.
In your terminal, from the root folder of this project, run:
yarn install
To obtain a deploy key, navigate to Subgraph Studio. You can also create your Subgraph from the WebApp and skip the next step.
In your terminal, run:
graph auth --studio <STUDIO_KEY>
In your terminal run:
graph create --studio <SUBGRAPH_NAME>
Where <SUBGRAPH_NAME>
is the name you are choosing for your Subgraph
In your terminal run:
graph deploy --studio <SUBGRAPH_NAME>
Where <SUBGRAPH_NAME>
is the name you are choosing for your Subgraph
Make sure to download Mainnet's smart contracts ABI from here and substitute it to the SSVNetwork.json
file in the abis
directory.
The networks.json
file contains a series of configurations specific to each network where the SSV Network smart contracts have been deployed. To switch from one to the other, simply run this command in your terminal:
graph build --network mainnet
Using the same network configuration file, it is possible to deploy for different networks. For example, to deploy for Mainnet, run this command in your terminal:
graph deploy --network mainnet --studio <SUBGRAPH_NAME>
(see this section for how to run a local Graph node)
To deploy the Subgraph to the local node, use the following command:
graph deploy --node http://localhost:8020 --ipfs http://localhost:5001 ssv-network
Wait for the Subgraph to index⏳
The Subgraph provides a GraphQL playground at the following URL: http://localhost:8000/subgraphs/name/ssv-network/
Test the Subgraph by running this query:
query MyQuery {
validators(where: {owner_: {id: "0xaA184b86B4cdb747F4A3BF6e6FCd5e27c1d92c5c"}}) {
id
owner {
id
}
operators {
id
}
cluster {
id
}
active
}
clusters(where: {owner_: {id: "0xaA184b86B4cdb747F4A3BF6e6FCd5e27c1d92c5c"}}) {
id
owner {
id
}
operatorIds
validatorCount
balance
active
}
}
The Subgraph can be deployed on the Graph Network, but for development purposes, a local Graph Node has been utilized. A guide on running a local Graph Node on Docker can be found here.
- TheGraph's official image is not M1 optimized
- A “Full” Docker was tested, but didn't work because the node's container kept crashing
- I have tried to build an M1-optimized image, as detailed here, it failed with
error: could not compile graph-node
- In the end, solution was to run ipfs and postgres in Docker, while compiling and running Graph Node (as suggested here)
cargo run -p graph-node --release -- \
--postgres-url postgresql://graph-node:let-me-in@localhost:5432/graph-node \
--ethereum-rpc https://goerli.infura.io/v3/c0c2ce3b9a6f43b4b6dd9f1a7b002fc7 \
--ipfs 127.0.0.1:5001
The initial version of the Subgraph was automatically generated by the init
scaffolding command:
graph init --allow-simple-name --node http://localhost:8020 \
--from-contract 0xC3CD9A0aE89Fff83b71b58b6512D43F8a41f363D \
--network goerli --abi ~/dev/ssv-network/SSVNetwork.json \
--protocol ethereum --contract-name SSVNetwork --index-events \
--start-block 9203578 ssv-network ssv-subgraph
⚠️ Make sure to download the contracts ABI (obtained here) and provide the path to it via the--abi
parameter.