Retrieve Balances
Last updated
Was this helpful?
Last updated
Was this helpful?
Retrieving balances involves converting an array of balances into a human-readable array of balances.
To access network features from your application, use our official libraries:
Requires Node >= 8.11.3 < 13.0.0
omg-js
library has 3 main objects that are used during all of the code samples. Here's an example of how to instantiate them:
web3_provider_url
- the URL to a full Ethereum RPC node (local or from infrastructure provider, e.g. ).
plasmaContractAddress
-CONTRACT_ADDRESS_PLASMA_FRAMEWORK
for defined .
watcherUrl
- the Watcher Info URL for defined (personal or from OMG Network).
The amount in balance array is defined in WEI (e.g. 429903000000000000
), the smallest denomination of ether, ETH. The currency
contains 0x0000000000000000000000000000000000000000
for ETH currency or a smart contract address (e.g. 0xd92e713d051c37ebb2561803a3b5fbabc4962431
) for ERC20 tokens.
Note, you can return the ERC20 balance only for one token at a time.
There's no direct way to retrieve balances on both Ethereum and OMG Network. Instead, you first retrieve an array of balances and then convert it to a preferred format.
Note, the amount for ERC20 tokens will be displayed in the lowest denomination of that particular token. You can convert it into a number via . For example, the provided address has multiple tokens with different decimals (18, 0, 18, 18, 6):
For example, if you want to convert the amount for TUSDT token (), you should either create a custom converter or use the web3.utils
as follows:
You can find the number of decimals for a given token on one of the blockchain explorers, such as .