Skip to content

AptosVM Balances

Fetch Aptos balance changes for versions 2382400000 to 2382410000 for asset 0x43782fca70e1416fc0c75954942dadd4af8d305a608b6153397ad5801b71e72d.

Code

Rust
use futures::StreamExt;
use std::{collections::HashSet, sync::Arc};
use pangea_client::{
    core::types::ChainId, query::Bound,
    ClientBuilder, Format, WsProvider,
    provider::MoveProvider, requests::movement::GetBalancesRequest, 
};
 
#[tokio::main]
async fn main() {
    dotenvy::dotenv_override().ok();
 
    let client = match ClientBuilder::default()
        .endpoint("aptos.app.pangea.foundation")
        .build::<WsProvider>()
        .await
    {
        Ok(client) => Arc::new(client),
        Err(e) => {
            eprintln!("Client failed to initialize:\n{e}");
            return;
        }
    };
 
    {
        let request = GetBalancesRequest { 
            chains: HashSet::from([ChainId::APTOS]), 
            from_block: Bound::Exact(2382400000), 
            to_block: Bound::Exact(2382410000), 
            address__in: HashSet::from(["0xc0deb00c405f84c85dc13442e305df75d1288100cdd82675695f6148c7ece51c"
            .parse() 
            .unwrap()]), 
            ..Default::default() 
        }; 
        let stream = match client 
            .get_move_balances_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

[
  ...
  {
    "block_number": 2382409979,
    "transaction_hash": "0xbf145769b152ca4a56e6e11edafc6322dd2f24cc7794833b0de847621977eb76",
    "timestamp": 1739913186953619,
    "address": "0x4c59c37e50d77e4d7bd36378aaa08ed340378627743c00e7d01e3c2099c19a26",
    "object": "0x5aecba53e34ba83c2bc4e37fa6f72c1049b4efe1bfa68d8bf2c48a2134eec195",
    "asset": "0x43782fca70e1416fc0c75954942dadd4af8d305a608b6153397ad5801b71e72d",
    "balance": 2500000000
  }
]

Query Parameters

  • chains: Filters the data by chain.
  • from_block / from_version: Filters the data by a starting version. As Move chains use a per-transaction versioned database, we use version interchangably with block_number and omit blocks altogether.
  • to_block / to_version: Filters the data by an ending version. As Move chains use a per-transaction versioned database, we use version interchangably with block_number and omit blocks altogether.
  • address__in: Filters the data by address.
  • object__in: Filters the data by object.
  • asset__in: Filters the data by asset.