Skip to main content

Subgraph Examples

This document provides a number of usable examples that you can use to obtain any information from the SSVNetwork smart contract using the subgraph.

The examples are provided in GraphQL to be used directly on the subgraph, Javascript to be used within code, or Curl to be used in any terminal.

These can be used on one of the two official Subgraphs deployed, Ethereum Mainnet or Holesky testnet.

info

In the below Javascript and Curl examples we are using the Holesky end point, to use the same queries on the Mainnet subgraph please use this endpoint:

https://api.studio.thegraph.com/query/71118/ssv-network-ethereum/version/latest

Account Nonce

Returns the nonce of an account.

query AccountNonceQuery {
account(id: "0x004f13516f00ccc4aca6560c115bee5aaf5f758b") {
nonce
}
}

Output:

{
"data": {
"account": {
"nonce": "5"
}
}
}

Cluster Snapshot

Returns the Cluster Snapshot needed in many smart contracts functions, like registering a validator.

warning

Note: the cluster's id is generated by concatenating the owner address and the operator IDs using a dash (-) separator.

query ClusterSnapshot {
cluster(id: "0x000b4369b71b6634f27f5de9cbaaabb0d21b8be5-399-429-694-699") {
validatorCount
networkFeeIndex
index
active
balance
}
}

Output

{
"data": {
"cluster": {
"validatorCount": "1",
"networkFeeIndex": "59597136600",
"index": "46367642388",
"active": true,
"balance": "19479447888000000000",
}
}
}

DAO constants and protocol network fee index

Returns the value of important values set by the DAO (such as Minimum Liquidation Collatera, and Liquidation Threshold Period), as well as the protocol-wide Network Fee Index, needed to calculate the balance of clusters and verify their risk of liquidation.

warning

Note: the id of daovalues is the address of the SSVNetwork smart contract deployed on the current chain. So in the case of Holesky it's 0x38A4794cCEd47d3baf7370CcC43B560D3a1beEFA

query daoValues {
daovalues(id: "0x38A4794cCEd47d3baf7370CcC43B560D3a1beEFA") {
declareOperatorFeePeriod
executeOperatorFeePeriod
liquidationThreshold
minimumLiquidationCollateral
networkFee
networkFeeIndex
networkFeeIndexBlockNumber
operatorFeeIncreaseLimit
operatorMaximumFee
}
}

Output

{
"data": {
"daovalues": {
"declareOperatorFeePeriod": "604800",
"executeOperatorFeePeriod": "604800",
"liquidationThreshold": "0",
"minimumLiquidationCollateral": "0",
"networkFee": "382640000000",
"networkFeeIndex": "0",
"networkFeeIndexBlockNumber": "208788",
"operatorFeeIncreaseLimit": "0",
"operatorMaximumFee": "76528650000000"
}
}
}

Cluster Balance Values

Returns all necessary data needed to compute the Cluster Balance.

query clusterBalanceValues {
_meta {
block {
number
}
}
daovalues(id: "0x38A4794cCEd47d3baf7370CcC43B560D3a1beEFA") {
networkFee
networkFeeIndex
networkFeeIndexBlockNumber
}
operators(where: {id_in: ["11", "13", "24", "29"]}) {
fee
feeIndex
feeIndexBlockNumber
}
cluster(id: "0xaa184b86b4cdb747f4a3bf6e6fcd5e27c1d92c5c-11-13-24-29") {
validatorCount
networkFeeIndex
index
balance
}
}

Output

{
"data": {
"daovalues": {
"networkFee": "382640000000",
"networkFeeIndex": "0",
"networkFeeIndexBlockNumber": "208788"
},
"operators": [
{
"fee": "0",
"feeIndex": "0",
"feeIndexBlockNumber": "377585"
},
{
"fee": "382640000000",
"feeIndex": "0",
"feeIndexBlockNumber": "412415"
},
{
"fee": "0",
"feeIndex": "0",
"feeIndexBlockNumber": "424818"
},
{
"fee": "0",
"feeIndex": "0",
"feeIndexBlockNumber": "426254"
}
],
"cluster": {
"validatorCount": "1",
"networkFeeIndex": "54511123984",
"index": "46719540456",
"active": true,
"balance": "10000000000000000000"
},
"_meta": {
"block": {
"number": 2373410
}
}
}
}

List of Validators for an owner

Returns a list of validators for an owner and displays whether they are active or not. Queries the first 5 validators owned by this address.

warning

Note: it's always best to limit the query, to avoid flooding the API, reduce performance issues, and in case of production API, spend too many credits.

query ListOfValidatorsPerOwner {
validators(
where: {owner: "0xcdb35fe42e19860b061ba6d1d85ce12c8f491ddf"}
first: 5
) {
id
owner {
id
}
active
}
}

Output

{
"data": {
"validators": [
{
"active": false,
"id": "0x80004ce97fc4747bcae7e061153deba256628f03825c431eccede3f588bd93aaa9b3486948f3c713e847f00bd7e01d08",
"owner": {
"id": "0x225702e8e1f34d2203857dd2bb8805c8b58c5cf8"
}
},
{
"active": true,
"id": "0x80008df886d57efe8906d7204b4e3c05d5983b22b34a1e3782557e492925fea7e7ff5edbfce46405a5e3714296eacac4",
"owner": {
"id": "0xd463eab729e4475620a9708428639948c7585227"
}
}
]
}
}

Validator Data by ID (Active status and Operator IDs)

Returns operator IDs and active status for a validator.

query ValidatorData {
validator(
id: "0x80006ff500fc36a6ae4ce7b643be3856ffe052ef36e5a6223dc9f7021b1dae02539c919751bba870f7ac9fccb86e06cf"
) {
removed
operators(first: 10) {
operatorId
}
}
}

Output

{
"data": {
"validator": {
"removed": true,
"operators": [
{
"operatorId": "10"
},
{
"operatorId": "5"
},
{
"operatorId": "8"
},
{
"operatorId": "9"
}
]
}
}
}

Cluster Data by ID (Balance, Active status and Operator IDs)

Returns balance, active status and operator IDs for a cluster.

warning

Note: the cluster's id