Retrieve Balances
Retrieving balances involves converting an RLP encoded array of balances into a human-readable array of balances.
Implementation
To access network features from your application, use our official libraries:
Requires Node >= 8.11.3 < 13.0.0
2. Import dependencies
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. Infura).
plasmaContractAddress
-CONTRACT_ADDRESS_PLASMA_FRAMEWORK
for defined environment.
watcherUrl
- the Watcher Info URL for defined environment (personal or from OMG Network).
3. Retrieve balances
There's no direct way to retrieve balances on both Ethereum and OMG Network. Instead, you first retrieve an RLP encoded array of BigNum balances and then convert it to a preferred format.
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.
3.1 Retrieve child chain (OMG Network) balances
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 web3.utils.fromWei
. 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 (0xd92e713d051c37ebb2561803a3b5fbabc4962431), 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 Etherscan.
3.2 Retrieve root chain (Ethereum) balances
Note, you can return the ERC20 balance only for one token at a time.
Last updated