# 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**

<table><thead><tr><th width="323">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>params:</code> <a href="#balancerequest"><img src="http://localhost:8080/assets/images/info.svg" alt="i"></a><code>BalanceRequest | BalanceRequest[]</code></td><td>A list of Balance Request Objects, specifying which addresses, and which assets to query</td></tr><tr><td><code>network?: string</code></td><td>Network to submit this request to. If omitted, will default to network the wallet is currently set to.</td></tr></tbody></table>

### BalanceRequest

<table><thead><tr><th width="343">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>address: string</code></td><td>Address to check balance(s)</td></tr><tr><td><code>assets?: string | string[]</code></td><td>Asset ID or script hash to check balance</td></tr><tr><td><code>fetchUTXO?: boolean</code></td><td>Fetches to UTXO data for NEO and/or GAS if attribute is 'true'</td></tr></tbody></table>

## **Success Response**

<table><thead><tr><th width="246">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>[address: string]:</code> <a href="#balanceresponse"><img src="http://localhost:8080/assets/images/info.svg" alt="i"></a><code>BalanceResponse[]</code></td><td>This key is the actual address of the query eg. "AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo"</td></tr></tbody></table>

### BalanceResponse

<table><thead><tr><th width="282">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>assetID: string</code></td><td>ID of the given asset</td></tr><tr><td><code>symbol: string</code></td><td>Symbol of the given asset</td></tr><tr><td><code>amount: string</code></td><td>Double Value of the balance represented as a String</td></tr><tr><td><code>unspent:</code> <a href="#utxo"><img src="http://localhost:8080/assets/images/info.svg" alt="i"></a><code>UTXO[]?</code></td><td>If fetch utxo's was turned on then the utxo array will be returned for the native assets NEO and GAS</td></tr></tbody></table>

### UTXO

<table><thead><tr><th width="283">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>asset: string</code></td><td>Script hash of the native asset</td></tr><tr><td><code>createdAtBlock: int</code></td><td>Block number where this utxo was created</td></tr><tr><td><code>index: int</code></td><td>Output index of the UTXO relative to the txid in which it was created</td></tr><tr><td><code>txid: string</code></td><td>The transaction id of this UTXO</td></tr><tr><td><code>value: string</code></td><td>The double value of this UTXO represented as a String</td></tr></tbody></table>

## Example

### Request

```js
neoline.getBalance({
  params: [
    {
      address: 'AUhp11NZfZEDKXWuSo5TPdGhnMx9wG2pdc',
      assets: ['GAS','MCT', '0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b', 'NEO']
    },{
      address: 'AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo'
    }
  ],
  network: 'TestNet'
})
.then((results) => {
  Object.keys(results).forEach(address => {
    const balances = results[address];
    balances.forEach(balance => {
      const { assetID, symbol, amount } = balance

      console.log('Address: ' + address);
      console.log('Asset ID: ' + assetID);
      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

```js
/* Single asset balance request sample */
// input
{
  params: {
    address: 'AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo',
    assets: ['NEO']
  },
  network: 'TestNet'
}

// output
{
  AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo: [
    {
      assetID: '0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b',
      symbol: 'NEO',
      amount: '6319'
    }
  ],
}

/* Single account balances request sample */
// input
{
  params: {
    address: 'AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo',
  },
  network: 'TestNet'
}

// output
{
  AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo: [
    {
      assetID: '0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b',
      symbol: 'NEO',
      amount: '6319'
    },
    {
      assetID: '0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7',
      symbol: 'GAS',
      amount: '2958.1094388'
    }
  ]
}

/* Multiple account balances request sample */
// input
{
  params: [
    {
      address: 'AUhp11NZfZEDKXWuSo5TPdGhnMx9wG2pdc'
    },
    {
      address: 'AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo',
      asset: 'NEO'
    }
  ],
  network: 'TestNet'
}

// output
{
  AUhp11NZfZEDKXWuSo5TPdGhnMx9wG2pdc: [
    {
      assetID: '0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7',
      symbol: 'NEO',
      amount: '1'
    },
    {
      assetID: '0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b',
      symbol: 'GAS',
      amount: '1'
    },
  ],
  AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo: [
    {
      assetID: '0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b',
      symbol: 'NEO',
      amount: '6319'
    },
    {
      assetID: '0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7',
      symbol: 'GAS',
      amount: '2958.1094388'
    }
  ]
}
```
