Overview of solutions for querying Ethereum with GraphQL

Julien Klepatch

Have you heard of GraphQL? That’s an alternative to REST apis that was created by Facebook. With GraphQL, clients specify the shape of the data they want, and backends figure out how to provide the desired data. No need to juggle with countless REST endpoints. GraphQL is becoming super popular this year, and web developers should absolutely learn it.

And now you can start using GraphQL with Ethereum too. Using the power of the GraphQL Standard Definition Language (SDL) and, you can easily make complex queries to the Ethereum blockchain and its smart contract. Let’s see what are the options for using GraphQL with Ethereum.


EthQL is a NodeJS library that provides a GraphQL api on top of the REST api of Ethereum.

It uses an Infura backend. If you have never heard of Infura, that is a service that save you the pain of running your own Ethereum nodes by providing publicly-accessible Ethereum nodes. To use EthQL, you need to first create an account on Infura, create a project in their dashboard, and put your Infura project ID in an environment variable.

Then, you run your EthQL server, and you can send it GraphQL requests. The EthQL API covers:

  • Block
  • Account
  • Transaction
  • Log
  • Decoded transaction

For example, this is a query for finding block info:

  block(number: 5450945) {
    parent {

On the frontend, you can use any GraphQL client that you want (Apollo, raw Graphql, etc…). All that matters is that you send your EthQL server queries it can understand. If you want to know more what the type of query you can send, check out this document.


TheGraph is a GraphQL api for Ethereum, available as a service. Contrary to EthQL, you don’t need to run any GraphQL server yourself. You only need to write Graphql queries, and send them to TheGraph server. Another difference is that TheGraph is focused on providing an interface for smart contracts, instead of the whole Ethereum API. And a last difference is that Dapp developers need to upload a description of the GraphQL interface of their smart contract (a “subgraph”) to TheGraph before it can add the contract to its public API.

If you want to know more about TheGraph, you can check this introduction in their documentation. And if you want to add a subgraph for your smart contract, you can check out this step-by-step tutorial. One interesting part is that they have CLI tools to speed-up the generation of a subgraph for a contract.


This project is an NodeJS tool to dynamically create a GraphQL schema of your smart contract. It will map a GraphQL Query or Mutation to all your Solidity functions, depending on whether they are read-only (view and pure) or not. You can use the GraphQL schema in any GraphQL server.

When you use this tool, you need to provide it with an url to an Ethereum node. You can run your own, or specify the url of a public node, like Infura.

EIP 1767

All of the projects I showed you before are great but you might wonder whether Ethereum itself has plans for GraphQL. Wouldn’t it be great if Ethereum clients themselves had a GraphQL API?

A team of volunteer have been working on a specification just for that. That’s the EIP 1767. If you are not familiar with EIPs (Ethereum Improvement Proposals), that is basically the Ethereum equivalent of internet RFCs (Request For Proposal), a collaborative process to create new standards.

When EIP 1167 will be finalized, Ethereum clients will start adding a GraphQL API. I dont think it will replace the REST api, but at least it will be a nice alternative way of fetching Ethereum data.

Lastly, there was also a project called Cleargraph to query Ethereum with GraphQL, but there were bought by another company, and it’s not clear whether or not the project is still active, so I just mention it for reference.

If you are a user of GraphQL or just curious, do try to use it in your future projects. The easiest way to get started and start playing around is to use TheGraph GraphQL api.


Leave a Reply

More great articles

Updates added to “Learn Ethereum Dapps” ebook – v1.1.0

Last week I released my ebook Learn Ethereum Dapps, where I teach how to build a ToDo list Dapp on…

Read Story

Create a Metaverse NFT

Since Facebook announced it’s rebranding into Meta, 

Metaverse projects became super hot. 

In this article I will show you how…

Read Story

The Smart contract 30 course is finished!

Finally! Smart contract 30 is finished! I have just published the last video of smart contract 30 on Solidity assembly.…

Read Story

Never miss a minute

Get great content to your inbox every week. No spam.
[contact-form-7 id="6" title="Footer CTA Subscribe Form"]