Skip to content

ERC20 Metadata

Block, transaction, and log data corresponds to when the ERC20 token was first indexed by Pangea, not when the contract was first deployed.

Fetch ERC20 metadata for blocks 21000000 to 21010000.

Code

Rust
use futures::StreamExt;
use std::{collections::HashSet, sync::Arc};
use pangea_client::{
    core::types::ChainId, query::Bound,
    ClientBuilder, Format, WsProvider,
    provider::Erc20Provider, requests::erc20::GetErc20Request, 
};
 
#[tokio::main]
async fn main() {
    dotenvy::dotenv_override().ok();
 
    let client = match ClientBuilder::default()
        .endpoint("app.pangea.foundation")
        .build::<WsProvider>()
        .await
    {
        Ok(client) => Arc::new(client),
        Err(e) => {
            eprintln!("Client failed to initialize:\n{e}");
            return;
        }
    };
 
    {
        let request = GetErc20Request { 
            chains: HashSet::from([ChainId::ETH]), 
            from_block: Bound::Exact(21000000), 
            to_block: Bound::Exact(21010000), 
            ..Default::default() 
        }; 
        let stream = match client 
            .get_erc20_by_format(request, Format::JsonStream, false) 
            .await
        {
            Ok(stream) => stream,
            Err(e) => {
                eprintln!("Request failed\n{e}");
                return;
            }
        };
 
        futures::pin_mut!(stream);
 
        while let Some(chunk) = stream.next().await {
            let chunk = String::from_utf8(chunk.unwrap()).unwrap();
            println!("{chunk}");
        }
    }
}

Response

[
  ...
  {
    "chain": 1,
    "first_seen_block_number": 21009996,
    "first_seen_block_hash": "0x6f054522b7ae88d8f82c45413d0e4c544e45fbeeb829c13ba25a1105c433047c",
    "first_seen_transaction_hash": "0x73c0c0145c432b756fa19e432b3c8b85ecf4170b135cf2d50b302c1046692f06",
    "first_seen_transaction_index": 2,
    "first_seen_log_index": 7,
    "address": "0xeca2ffd283841122142c6cdf161149075777fde1",
    "name": "Vitalik's 2017 Git",
    "symbol": "CASPER",
    "decimals": 9
  }
]

Query Parameters

  • chains: Filters the data by specific blockchain networks.
  • from_block: Filters the data by a starting block number.
  • to_block: Filters the data by an ending block number.
  • address__in: Filters the data by a list of ERC20 contract address.
  • symbol__in: Filters the data by a list of token symbol.
  • name__in: Filters the data by a list of token name.
  • decimals__gte: Filters the data by token decimal using the greater than or equal to operator.
  • decimals__lte: Filters the data by token decimal using the less than or equal to operator.