Skip to content

ERC20 Approvals

Fetch ERC20 approvals for blocks 21000000 to 21000100 for WBTC 0x2260fac5e5542a773aa44fbcfedf7c193bc2c599.

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::GetErc20ApprovalsRequest, 
};
 
#[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 = GetErc20ApprovalsRequest { 
            chains: HashSet::from([ChainId::ETH]), 
            from_block: Bound::Exact(21000000), 
            to_block: Bound::Exact(21010000), 
            address__in: HashSet::from(["0x2260fac5e5542a773aa44fbcfedf7c193bc2c599"
            .parse() 
            .unwrap()]), 
            ..Default::default() 
        }; 
        let stream = match client 
            .get_erc20_approval_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,
    "block_number": 21000089,
    "block_hash": "0xc9d7228978bbfc4a314ed1e1b536ec5a7a3ac8f749d4e5238ed6e9de1fbd64d3",
    "transaction_hash": "0xa9d5391d10b8b9a6e2d3bcb28325833a553766831d86dda7f4a408192594b513",
    "transaction_index": 89,
    "log_index": 314,
    "address": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
    "name": "Wrapped BTC",
    "symbol": "WBTC",
    "decimals": 8,
    "owner": "0xa58aef2608a4c1d687f2e85a8c45d8fd5c720e37",
    "spender": "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae",
    "value": 2
  }
]

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.
  • owner__in: Filters the data by a list of ERC20 token owner.
  • spender__in: Filters the data by a list of ERC20 token spender.
  • value__gte: Filters the data by value using the greater than or equal to operator.
  • value__lte: Filters the data by value using the less than or equal to operator.
  • 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.