Get Account Balance

Get Account Balance

Overview

This node retrieves the balance information of a specified account on the NEAR blockchain network. It connects to either the mainnet or testnet based on user input and fetches detailed balance data including available, total, staked, and state-staked amounts. This node is useful for monitoring account balances in decentralized applications, wallets, or any workflow that requires up-to-date NEAR account financial data.

Practical examples:

  • Automatically checking the balance of a user's NEAR account before initiating a transaction.
  • Monitoring staking status and available funds for an account in a DeFi application.
  • Integrating balance checks into automated reporting or alerting workflows.

Properties

Name Meaning
Network ID The NEAR network to connect to. Options include "mainnet" (the main NEAR network) and "testnet" (the NEAR test network).
Account ID The NEAR account identifier whose balance you want to retrieve, e.g., example.near.
Frac Digits Number of decimal places to use when formatting the balance amounts for display purposes.

Output

The node outputs an array of items where each item contains a json object with the following structure:

  • balance: Raw balance data as returned by the NEAR API, including fields such as available, total, staked, and stateStaked.
  • formatted: Human-readable string representations of the balances formatted according to the specified number of fractional digits:
    • available: Available balance formatted as a NEAR amount string.
    • total: Total balance formatted as a NEAR amount string.
    • staked: Staked balance formatted as a NEAR amount string.
    • stateStaked: State staked balance formatted as a NEAR amount string.

No binary data output is produced by this node.

Dependencies

  • Requires access to the NEAR blockchain RPC endpoints. The node uses predefined URLs for both mainnet and testnet networks.
  • No additional external credentials are required beyond specifying the network and account ID.
  • Uses the near-api-js library internally to interact with the NEAR blockchain.

Troubleshooting

  • Common issues:

    • Invalid or non-existent account ID will cause errors when fetching balance.
    • Network connectivity problems may prevent connecting to the NEAR RPC nodes.
    • Using an unsupported network ID will result in failure to connect.
  • Error messages and resolutions:

    • Errors related to account not found: Verify the account ID is correct and exists on the selected network.
    • Connection errors: Check internet connection and ensure the NEAR RPC URLs are accessible.
    • If the node throws an error but "Continue On Fail" is enabled, the error details will be included in the output for easier debugging.

Links and References

Discussion