Building Your Own ERC-20 API: A Complete Guide

Substreams By Feb 13, 2024 No Comments

A comprehensive guide for building an ERC-20 API using Substreams.

TL;DR: Get a detailed guide on how to build a custom ERC-20 API using Substreams.

Are you a developer seeking to leverage historical blockchain data in your dApp? If yes, this article is tailored for you. In this blog, we will explain the step-by-step process for building an ERC-20 API. Join us for a great learning experience!

But before we dive into the nitty-gritty of the how, let’s uncover the compelling reasons why developers should opt to craft their own custom API.

Why build your own custom API?

Accessing blockchain data, particularly historical data, is difficult due to the lack of standardization and the intricate data processing needs. Building a custom API can be a viable solution to these challenges. It offers several advantages over other solutions:

  1. Customization: Crafting a custom API enables developers to precisely tailor solutions to their needs, ensuring seamless alignment with dApp requirements for enhanced efficiency and functionality.
  2. Control Over Data Extraction: Custom APIs empower developers with precise control over data extraction, allowing the selection of tailored methods to suit project demands. In this guide, we’ll utilize Substreams, a data processing engine built by StreamingFast.
  3. Optimized Performance: By developing a custom API, developers can fine-tune performance, resulting in faster and more responsive interactions with blockchain data, ultimately improving the overall user experience.
  4. Flexibility and Scalability: A custom API offers unparalleled flexibility and scalability, enabling developers to adapt and expand their API as the project evolves over time.

Understanding the architecture for building your ERC-20 API

Creating your custom API involves three main phases:

  1. Data extraction
  2. Data storage
  3. Construction of developer-friendly API services coupled with comprehensive documentation

We’ll use Substreams to grab data from the blockchain and ClickHouse to store the extracted data. For the creation of developer-friendly API services and docs, we’ll use Swagger.

Phase 1: Extracting data using Substreams

In the first phase, data extraction, we’ll use Substreams, a powerful blockchain indexing technology. It enables developers to write Rust modules to compose data. These modules are composable, breaking down the entire dataset into smaller streams of data that can be reused within other Substreams, allowing developers to build onto the work of others.

The modules are capable of sorting, sifting, temporarily storing, and transforming blockchain data from block objects and smart contracts. The resulting processed data can then be utilized in data sinks, such as databases like ClickHouse.

At present, Substreams can only be built using Rust, but the StreamingFast team, creators of Substreams, has plans to enable developers to build Substreams in Go and Typescript in the near future.

We will extract information on balance changes, transfers, contract details (name, symbol), and total supply for all ERC-20 contracts. Additionally, we’ll also use the ClickHouse sink, a project by Pinax, to channel blockchain data into the ClickHouse database. You can learn more about ClickHouse sink from our blog post, Simplify Real-Time Blockchain Analytics with ClickHouse.

Phase 2: Storing data using ClickHouse

For the second phase, which involves data storage, we’ll use ClickHouse, a high-performance, column-oriented SQL database management system (DBMS) designed for online analytical processing (OLAP).

ClickHouse is an ideal choice for storing blockchain data due to its capability to handle massive amounts of data and faster query times. To learn more about ClickHouse, you can refer to the official ClickHouse documentation.

Phase 3: Developing API using Swagger

The final stage involves the creation of developer-friendly API services and comprehensive documentation. For this, we’ll use Swagger, a platform that simplifies API development with the OpenAPI Specification (OAS).

Swagger saves a lot of time in writing API documentation by running through the OAS to ensure you meet the guidelines. It offers a set of open-source tools built to help programmers develop, design, document, and use REST APIs. Learn more about Swagger in this beginner’s guide.

Wrapping up

As we wrap up, it’s clear that the process of building a custom ERC-20 API involves a keen understanding of the right tools and technologies. By leveraging Substreams for data extraction, ClickHouse for data storage, and Swagger for API development, developers can effectively create flexible, efficient, and functional APIs. This not only enhances the user experience but also empowers developers to adapt to evolving project requirements.

It’s an exciting journey, and we hope this guide sets you on the path to creating your own unique APIs in the blockchain space.

Additional resources

For a more in-depth understanding and practical application of the concepts discussed in this guide, we recommend checking out our GitHub repository, Substreams ERC20 API. Here, you can explore and test the API we’ve created.

Please note that our API is not production-ready as it is in active development.
👉 To get API access to blockchain data free for a limited time, register at Pinax. Get your API keys today!
💡 This article answers questions like:
- Why would a developer create a custom API?
- What tools and technologies does a developer need to create an ERC-20 API?
- What are the steps to create an ERC-20 API?
Author

I am a seasoned technical writer with a passion for simplifying complex tech topics, especially tech around blockchain and web3. Beyond writing, I also love coding as a hobby, with Rust being a particular favorite. This dual passion enables me to bridge the gap between technical intricacies and accessible content.

No Comments

Leave a comment

Your email address will not be published. Required fields are marked *