getBalance

Return balance of a specific asset for the given account.

If the asset is omited from a request to MainNet, all asset and token balances will be returned.

Input Arguments

ParameterDescription

A list of Balance Request Objects, specifying which addresses, and which assets to query

BalanceRequest

ParameterDescription

address: string

Address to check balance(s)

contracts: string[]

contracts is a list of contract hash

Success Response

ParameterDescription

This key is the actual address of the query eg. "NdJqYNVK99srFABQDLPdrpz2By1RX1sLvr"

BalanceResponse

ParameterDescription

contract: string

contract of the given hash

symbol: string

Symbol of the given contract

amount: string

Double Value of the balance represented as a String

Example

Request

neolineN3.getBalance()
.then((results) => {
    Object.keys(results).forEach(address => {
        const balances = results[address];
        balances.forEach(balance => {
            const { contract, symbol, amount } = balance

            console.log('Address: ' + address);
            console.log('contract: ' + contract);
            console.log('Asset symbol: ' + symbol);
            console.log('Amount: ' + amount);
        });
    });
})
.catch((error) => {
    const {type, description, data} = error;
    switch(type) {
        case 'NO_PROVIDER':
            console.log('No provider available.');
            break;
        case 'CONNECTION_DENIED':
            console.log('The user rejected the request to connect with your dApp');
            break;
        default:
            // Not an expected error object.  Just write the error to the console.
            console.error(error);
            break;
    }
});

Response

[
    {
        "symbol": "NEO",
        "amount": "5000000",
        "contract": "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5"
    },
    {
        "symbol": "GAS",
        "amount": "10063.4476161",
        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf"
    }
]

最后更新于