Skip to content
Discussion options

You must be logged in to vote

Aptos has support for view functions. This is a view function in the coin module in the framework:

#[view]
/// Returns the balance of `owner` for provided `CoinType`.
public fun balance<CoinType>(owner: address): u64 acquires CoinStore {
    assert!(
        is_account_registered<CoinType>(owner),
        error::not_found(ECOIN_STORE_NOT_PUBLISHED),
    );
    borrow_global<CoinStore<CoinType>>(owner).coin.value
}

From here.

You can query it like this with the Python SDK:

client = RestClient("https://api.mainnet.aptoslabs.com/v1")
func = "0x1::coin::balance"
type_arguments = ["0x1::aptos_coin::AptosCoin"]
arguments = ["0x123"]
await client.view(func, type_arguments, arguments)

Here is ho…

Replies: 1 comment 2 replies

Comment options

banool
Mar 7, 2024
Maintainer Author

You must be logged in to vote
2 replies
@karamelniycoder
Comment options

@gregnazario
Comment options

Answer selected by 0x-j
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
move Questions related to the Move Language
3 participants