NeoLine
English
English
  • Welcome to NeoLine
  • 🌵Download NeoLine Wallet
    • Mobile
      • Download iOS Version
      • Download Android Version
    • Google Chrome Extension
      • Download Google Chrome Extension
  • 🧩Create and Manage Neo X Wallet
    • Create Neo X (EVM) Wallet
    • Import Neo X (EVM) wallet
    • How to Bridge GAS Using the NeoLine Chrome Extension?
    • How to add and switch networks?
    • About NeoLine Activity
  • 🙂N3 Wallet
    • Neo N3 Wallet User Guide
      • Neo N3 Wallet | Mobile
      • Neo N3 Wallet | NeoLine Chrome Extension
    • Neo N3 Migration Guide
      • Neo N3 Migration Guide | Mobile
      • Neo N3 Migration Guide | NeoLine Chrome Extension
  • 🔒Hardware Wallet
    • Ledger Hardware Wallet
  • 🌈Getting Started
    • How to Securely and Correctly Backup Your Wallet?
    • One Pass Setting for NeoLine Extension Wallet
    • How to Use the Address Book?
    • How to Speed Up or Cancel a Pending Transaction?
    • How to Delete Unused Wallet Accounts in the NeoLine Wallet?
    • Manage Assets
      • How to Add/Manage Assets?
      • How to Add NFTs
      • How to Use NeoLine Wallet for Transfer and Receive
      • How to Transfer to Other Wallets/Exchanges
    • FAQ
  • Reference
    • Neo3 provider API
      • Read Methods
        • getProvider
        • getBalance
        • getStorage
        • invokeRead
        • invokeReadMulti
        • verifyMessage
        • verifyMessageV2
        • getBlock
        • getTransaction
        • getApplicationLog
        • pickAddress
        • AddressToScriptHash
        • ScriptHashToAddress
      • Write Methods
        • send
        • invoke
        • invokeMultiple
        • signMessage
        • signMessageV2
        • signMessageWithoutSalt
        • signMessageWithoutSaltV2
        • signTransaction
        • switchWalletNetwork
        • switchWalletAccount
      • Common Methods
        • getNetworks
        • getAccount
        • getPublicKey
      • Common Events
        • READY
        • ACCOUNT_CHANGED
        • CONNECTED
        • DISCONNECTED
        • NETWORK_CHANGED
        • BLOCK_HEIGHT_CHANGED
        • TRANSACTION_CONFIRMED
      • Event Methods
        • addEventListener
        • removeEventListener
      • Errors
        • Errors
    • Neo2 provider API
      • Read Methods
        • getProvider
        • getNetworks
        • getAccount
        • getPublicKey
        • getBalance
        • getStorage
        • invokeRead
        • verifyMessage
        • getBlock
        • getTransaction
        • getApplicationLog
      • Write Methods
        • send
        • invoke
        • invokeMulti
        • signMessage
        • deploy
        • switchWalletNetwork
        • switchWalletAccount
      • Events
        • READY
        • ACCOUNT_CHANGED
        • CONNECTED
        • DISCONNECTED
        • NETWORK_CHANGED
        • BLOCK_HEIGHT_CHANGED
        • TRANSACTION_CONFIRMED
      • Event Methods
        • addEventListener
        • removeEventListener
      • Errors
        • Errors
    • Ethereum provider API
    • JSON-RPC API
      • eth_requestAccounts
      • eth_accounts
      • eth_chainId
      • personal_sign
      • eth_signTypedData_v4
      • eth_sendTransaction
      • wallet_addEthereumChain
      • wallet_switchEthereumChain
      • wallet_watchAsset
  • 💬Contact Us
    • Contact Us
由 GitBook 提供支持
在本页
  • Input Arguments
  • BalanceRequest
  • Success Response
  • BalanceResponse
  • UTXO
  • Example
  • Request
  • Response

这有帮助吗?

  1. Reference
  2. Neo2 provider API
  3. Read Methods

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

Parameter
Description

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

network?: string

Network to submit this request to. If omitted, will default to network the wallet is currently set to.

BalanceRequest

Parameter
Description

address: string

Address to check balance(s)

assets?: string | string[]

Asset ID or script hash to check balance

fetchUTXO?: boolean

Fetches to UTXO data for NEO and/or GAS if attribute is 'true'

Success Response

Parameter
Description

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

BalanceResponse

Parameter
Description

assetID: string

ID of the given asset

symbol: string

Symbol of the given asset

amount: string

Double Value of the balance represented as a String

If fetch utxo's was turned on then the utxo array will be returned for the native assets NEO and GAS

UTXO

Parameter
Description

asset: string

Script hash of the native asset

createdAtBlock: int

Block number where this utxo was created

index: int

Output index of the UTXO relative to the txid in which it was created

txid: string

The transaction id of this UTXO

value: string

The double value of this UTXO represented as a String

Example

Request

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

/* 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'
    }
  ]
}
上一页getPublicKey下一页getStorage

最后更新于7个月前

这有帮助吗?

params: BalanceRequest | BalanceRequest[]

[address: string]: BalanceResponse[]

unspent: UTXO[]?