Cover Image for ETH2 API — Beacon chain API data?

ETH2 API — Beacon chain API data?

ETH2

On Nov 24th, 2020, Ethereum 2.0 Beacon chain is launched and has more than 1.5 million ETH deposited in the ETH2 smart contract and with ~50K validators when writing this article.

Today, we will show how to get ETH2.0 data using our GrpahQL APIs. You can also visualize different types of ETH2 data metrics on our ETH2 explorer. If you want to learn about the Beacon chain’s inner workings, read this article.

ETH2 Deposits API

As soon as the ETH2.0 deposit smart contract launched, everyone was tracking the number of ETHs deposited in the contract. Because to launch the Beacon chain, it needs to cross the threshold of 524,288 ether. Additionally, the number of ETH staked (number of validators) directly impacts ETH2.0 inflation.

You can now use this API to get the amount of ETH deposited, the number of validators, and deposits.

query ($network: Ethereum2Network!, $from: ISO8601DateTime, $till: ISO8601DateTime) {
  ethereum2(network: $network) {
    deposits(date: {since: $from, till: $till}) {
      count
      amount
      validators: count(uniq: validators)
    }
  }
}
{
  "limit": 10,
  "offset": 0,
  "network": "eth2",
  "from": "2024-01-25",
  "till": "2024-02-01T23:59:59",
  "dateFormat": "%Y-%m-%d"
}

ETH2 deposit count and amount daily

Let’s say you want to track daily ETH deposits on Ethereum2 smart contract. For that, you use the following query.


query ($network: Ethereum2Network!, $dateFormat: String!, $from: ISO8601DateTime, $till: ISO8601DateTime) {
  ethereum2(network: $network) {
    deposits(options: {asc: "date.date"}, date: {since: $from, till: $till}) {
      date: date {
        date(format: $dateFormat)
      }
      count: countBigInt
      amount
    }
  }
}
{
  "limit": 10,
  "offset": 0,
  "network": "eth2",
  "from": "2024-01-25",
  "till": "2024-02-01T23:59:59",
  "dateFormat": "%Y-%m-%d"
}

Top Validators based on the deposit amount

You need to deposit 32ETH to become a validator for the Beacon chain. Use this query to learn about the top validators based on the deposit amount.

query ($network: Ethereum2Network!, $limit: Int!, $offset: Int!, $from: ISO8601DateTime, $till: ISO8601DateTime) {
  ethereum2(network: $network) {
    validatorUpdates(
      options: {desc: "validatorBalanceChange", limit: $limit, offset: $offset}
      date: {since: $from, till: $till}
    ) {
      validator {
        index
        pubkey
      }
      validatorBalanceChange
    }
  }
}
{
  "limit": 10,
  "offset": 0,
  "network": "eth2",
  "from": "2024-01-25",
  "till": "2024-02-01T23:59:59",
  "dateFormat": "%Y-%m-%d"
}

ETH2 Blocks

The Beacon Chain provides the heartbeat to Ethereum 2.0. This beat is a 12-second slot in which validators can propose blocks. 32 slots make an epoch.

ETH2 Beacon chain

If you want to know about the count for blocks, slots, and block proposers, use the query below.

Daily Blocks and Deposits count

To obtain a daily summary of Ethereum 2.0 blocks and deposit counts, the following query can be run here

query MyQuery {
  ethereum2(network: eth2) {
    blocks(options: {limit: 10, desc: "date.date"}) {
      count
      date {
        date
      }
    }
  }
}

For insight into daily deposit activities, you can run the below query here This query provides a day-wise breakdown of deposit counts and amounts, organized in ascending order by date, which can be instrumental for analyzing deposit trends.

query ($network: Ethereum2Network!, $dateFormat: String!, $from: ISO8601DateTime, $till: ISO8601DateTime) {
  ethereum2(network: $network) {
    deposits(options: {asc: "date.date"}, date: {since: $from, till: $till}) {
      date: date {
        date(format: $dateFormat)
      }
      count: countBigInt
      amount
    }
  }
}
{
  "limit": 10,
  "offset": 0,
  "network": "eth2",
  "from": "2024-01-17",
  "till": "2024-01-23T23:59:59",
  "dateFormat": "%Y-%m-%d"
}

Attestations

The Beacon chain create groups of validators, called Committees. One validator in this group proposes the block, and the other validators vote on the proposed block. These votes are called attestations.

The following API gives you the number of unique attestations. You can run it here

{
  ethereum2(network: eth2) {
    attestations(
      options: {asc: "date.date"}
      date: {since: "2024-01-16", till: "2024-01-23"}
      validatorIndex: {is: 1142403}
    ) {
      date: date {
        date(format: "%Y-%m-%d")
      }
      count: countBigInt
    }
  }
}


Proposer Slashing

Ethereum2.0 usage Proof of stake, where honest validators incentivized and dishonest or incompetent validators get punished, is called slashing. In Ethereum2.0 slashing occurs because

  • Block producer proposes two conflicting blocks within the same slot
  • Or vote more than once with conflicting checkpoint (Chain creates a checkpoint after every 32 blocks)

Bitquery's ETH2 Proposer API gives you information on recent proposer slaashing including proposer, block and related ETH1 information.

query MyQuery {
  ethereum2(network: eth2) {
    proposerSlashings(options: {limit: 10, desc: "block.timestamp.time"}) {
      proposer {
        index
      }
      slashing {
        bodyRoot
        epoch
      }
      eth1 {
        blockHash
        depositCount
        depositRootHash
      }
      block {
        height
        timestamp {
          time
        }
      }
    }
  }
}


Attestor Slashing

Attestors also get slashed if they don’t vote honestly or show incompetency. Use this query to track recent attestor slashing events on the Becaon Chain.

query ($network: Ethereum2Network!, $dateFormat: String!) {
  ethereum2(network: $network) {
    attesterSlashings(options: {desc: "date.date"}, date: {after: "2024-01-29"}) {
      date: date {
        date(format: $dateFormat)
      }
      parentRoot
      eth1 {
        depositCount
        depositRootHash
        blockHash
      }
      stateRoot
      validator {
        pubkey
        index
      }
    }
  }
}

{
  "limit": 10,
  "offset": 0,
  "network": "eth2",
  "dateFormat": "%Y-%m-%d"
}

Validators Information API

Using our APIs, you can get all sorts of information about one or multiple validators. For example, the following APIs give you blocks proposed by a validator number (45871).

The query below gives you the slot attestations of a validator (45871).

We showed you some examples of our ETH2 APIs; you get all sorts of different ETH2 data using our APIs. Just explore our GraphQL schema to learn the capabilities of ETH2 APIs. If you have any questions about our APIs, ask them our Telegram group.

Also, Read

About Bitquery

Bitquery is a set of software tools that parse, index, access, search, and use information across blockchain networks in a unified way. Our products are:

  • Coinpath® APIs provide blockchain money flow analysis for more than 24 blockchains. With Coinpath’s APIs, you can monitor blockchain transactions, investigate crypto crimes such as bitcoin money laundering, and create crypto forensics tools. Read this to get started with Coinpath®.

  • Digital Assets API provides index information related to all major cryptocurrencies, coins, and tokens.

  • DEX API provides real-time deposits and transactions, trades, and other related data on different DEX protocols like Uniswap, Kyber Network, Airswap, Matching Network, etc.

If you have any questions about our products, ask them on our Telegram channel or email us at sales@bitquery.io. Also, subscribe to our newsletter below, we will keep you updated with the latest in the cryptocurrency world.

Subscribe to our newsletter

Subscribe and never miss any updates related to our APIs, new developments & latest news etc. Our newsletter is sent once a week on Monday.