Exclusive Tutorial: Access ERC20 Token Data for Your Apps

Pinax, Substreams By Oct 15, 2024 1 Comment

Devs! Learn how to set up this ERC20 Token API—it’s free and open source.

TL;DR: Pinax’s open-source ERC20 Token API offers developers an easy, customizable way to access real-time and historical token data, like balances, holders, and transfers, across EVM and Antelope chains.

Have you ever needed to fetch comprehensive ERC20 token data for your blockchain application?

Pinax has solved this problem by developing a free, open-source API that enables developers to pull token data like supply, holders, and transfers for popular tokens like USDC, BNB, and USDT.

This tutorial will walk you through setting up the API, configuring a ClickHouse database, and fetching the essential token data from both EVM and Antelope chains.

Why access ERC20 token data with Pinax?

Accessing detailed token data like balances, holders, and historical supply is a challenge for developers. While services like Etherscan offer token data, they often lack flexibility for developers who want to integrate this data into their own applications.

With Pinax’s ERC20 Token API tutorial, developers can now:

  • Retrieve token supply for various tokens and blockchains.
  • Access historical data, allowing you to fetch token information at specific block heights.
  • List the top holders of a particular token contract.
  • Fetch token balances for any address across multiple chains.
  • Obtain transfer data, including transaction details from contracts and addresses.

Substreams, which powers the Pinax API, plays a crucial role in this process. Substreams allows the indexing of large volumes of blockchain data at unprecedented speeds. By leveraging Substreams, the API can efficiently sync, index, and serve data across multiple blockchains, ensuring that developers have access to both real-time and historical data without any bottlenecks.

The best part?

It’s entirely open source, so you can modify it to fit your needs and run it on your own infrastructure for free.

While the API hasn’t been deployed yet, Pinax plans to release it in the future, providing a simple and powerful solution for all developers. In the meantime, you can explore and run the code on your own setup.

If you have an app that needs token data, our ERC20 Token API can provide it for you. It’s open source, free, and customizable—allowing you to fetch data like supply, balances, holders, and transfers across EVM chains.

Mathieu, Pinax Dev
A diagram of the ERC20 Token API system, showing relationships between Typespec, Substreams, ClickHouse, and the API code.
Architecture of the Pinax ERC20 Token API system: integrating TypeSpec, Substreams, and ClickHouse for efficient data handling.

Types of data you can extract

Set up Pinax’s ERC20 Token API to access several key types of blockchain data essential for building token-related applications. Here are the primary types of data you can extract using the API:

  • Transfers: Fetch detailed information on ERC20 token transfers, including transaction IDs and sender/receiver addresses.
  • Supply: Retrieve the total supply of any ERC20 token in real-time or at a specified historical block height.
  • Contract information: Obtain key information about a token, such as its name, symbol, and decimals.
  • Balances: Access balance changes for any token and address across various EVM and Antelope chains.

The table below provides a summary of the data you can extract:

EventDescription
[Transfers]Get ERC20 transfers
[Supply]Get the total supply for every token
[Contract]Get token information (name, symbol, decimals)
[Balances]Get all balance changes
💡 This data is essential for developers who need to work with tokens, perform analytics, or build decentralized applications that rely on blockchain data.
A diagram showing the different types of data you can extract with Pinax's ERC20 Token API: transfers, supply, contracts, balance changes.
Overview of the types of data extracted by the Pinax ERC20 Token API and a Mermaid diagram showing how blockchain events map to database outputs.

Setting up the API: step-by-step guide

Let’s walk through the process of setting up Pinax’s ERC20 Token API. To get started, you’ll need a few prerequisites.

1. Clone the GitHub repository

First, head to the Pinax ERC20 Token API GitHub repository and clone the project:

git clone <https://github.com/pinax-network/erc20-token-apis.git>

2. Install and set up ClickHouse

The Pinax API uses ClickHouse, a fast and powerful database, to store blockchain data. Install ClickHouse by visiting their website:

# Start the ClickHouse server
clickhouse-server

After starting the server, you’ll need to create the database schema:

# Create the required database
CREATE DATABASE erc20_tokens_v1;
# Apply the schema from the repository
RUN schema.sql;

3. Start the Substreams Sink SQL

Next, you’ll use Substreams Sink SQL to index blockchain data and populate your ClickHouse database. This step might take some time depending on the chain, but it ensures you have all token data available.

# Start syncing data from the blockchain
substreams-sink-sql run $CLICKHOUSE_URL substreams.yaml

4. Generate API keys

Pinax provides tokens to access the blockchain data stream. Visit the Pinax app to obtain your tokens, then export them in your terminal:

export SUBSTREAM_TOKENS=<your_api_token>

5. Launch the API

Once your data is synced and the tokens are set, run the API:

# Start the API
npm start

By default, the API will be available on port 3000, and you can now start making requests to fetch token data.

Fetching ERC20 token data

With the API running, here are some examples of how you can fetch specific token data.

  • Retrieve token supply for USDT on Ethereum:
GET /supply?token=USDT&blockchain=ethereum
  • Get top holders for a token contract:
GET /holders?contract=0x1234&limit=10
  • Fetch token balances for an address:
GET /balances?address=0xabcd
  • Retrieve transfer data for a specific contract:
GET /transfers?contract=0x5678

These endpoints provide flexibility for developers looking to build applications that rely on real-time or historical blockchain data.

Why setting up Pinax’s API is the right choice

Pinax’s ERC20 Token API stands out for its ease of use, open-source nature, and the ability to run it locally or on your infrastructure. Unlike paid APIs, Pinax gives you full control and customization while providing access to both historical and real-time blockchain data. You can also choose to use our hosted service if you don’t want to manage your own setup.

With Pinax’s ERC20 Token API, developers no longer need to rely on third-party services for blockchain data. Whether you want to track token supply, fetch holder data, or get real-time transaction information, Pinax provides a flexible, open-source solution. Set up your own instance or stay tuned for our deployed API and start building powerful blockchain applications.

Get started with Pinax

💡 This article answers questions like:
- Why a developer should access ERC20 token data with Pinax’s API tutorial?
- What types of ERC20 token data can a developer extract with Pinax’s API tutorial?
- What use cases could a developer use the ERC20 Token API for?
- What prerequisites does a developer need to set up the ERC20 Token API?
- What are some examples of how a developer can fetch specific token data?

Author

I am a dedicated member of the Graph Advocates DAO and proud to be a part of the Graphtronauts community. As a passionate crypto investor and enthusiast, I have delved into the world of decentralized technologies, with a strong focus on The Graph protocol. My journey includes writing insightful blogs for Graphtronauts and contributing to the development of subgraph documentation for various projects within The Graph ecosystem. Most recently, I have taken on the role of a Pinax technical writer, further expanding my commitment to advancing the adoption and understanding of blockchain and Graph-based technologies. /n https://twitter.com/PaulBarba12 https://github.com/PaulieB14 https://hey.xyz/u/paulieb https://medium.com/@paulieb.eth/about

1 Comment

  1. Twila says:

    Hi there! I’m at work browsing your blog from my new apple iphone!
    Just wanted to say I love reading through your blog and look forward to all your posts!
    Keep up the great work!

Leave a comment

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