Git Product home page Git Product logo

ssv-subgraph's Introduction

SSV-Subgraph

This Subgraph is indexing the SSVNetwork smart contract through the Events emitted.

Install dependencies

In your terminal, from the root folder of this project, run:

yarn install

Deploy

Deploy to Subgraph studio

Authenticate with Subgraph Studio

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>  

Create a Subgraph on Studio

In your terminal run:

graph create --studio <SUBGRAPH_NAME>

Where <SUBGRAPH_NAME> is the name you are choosing for your Subgraph

Deploy

In your terminal run:

graph deploy --studio <SUBGRAPH_NAME>

Where <SUBGRAPH_NAME> is the name you are choosing for your Subgraph

Deploy this Subgraph for Mainnet

Obtain Mainnet ABI

Make sure to download Mainnet's smart contracts ABI from here and substitute it to the SSVNetwork.json file in the abis directory.

Rebuild the project for Mainnet

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
Deploy the project for 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>

Deploy Subgraph locally

(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⏳

Query indexed data

The Subgraph provides a GraphQL playground at the following URL: http://localhost:8000/subgraphs/name/ssv-network/

Query example

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
  }
}

Run local Graph Node

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.

Note on M1 chips

  • 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

Project scaffolding

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.

ssv-subgraph's People

Contributors

raekwoniii avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.