ontio / ontology

Official Go implementation of the Ontology protocol. https://dev-docs.ont.io/#/
GNU Lesser General Public License v3.0
829 stars 289 forks source link

How can I query an address' all token balances via RPC API? #1281

Open heshuchao opened 4 years ago

heshuchao commented 4 years ago

the response of RPC-API-"getbalance" only contains the balance of ont and ong.

what if I need response like below

{"code":0,"msg":"SUCCESS","result":[{"balance":"580667.517022225","asset_name":"ong","asset_type":"native","contract_hash":"0200000000000000000000000000000000000000"},{"balance":"0","asset_name":"waitboundong","asset_type":"native","contract_hash":"0200000000000000000000000000000000000000"},{"balance":"0","asset_name":"unboundong","asset_type":"native","contract_hash":"0200000000000000000000000000000000000000"},{"balance":"77309","asset_name":"ont","asset_type":"native","contract_hash":"0100000000000000000000000000000000000000"},{"balance":"1608222085.94387794","asset_name":"MBL","asset_type":"oep4","contract_hash":"e5a49d7fd57e7178e189d3965d1ee64368a1036d"}]}

https://explorer.ont.io/v2/addresses/AaXXsKujBcwR9aB5NgNErgsB7eM9CTYByw/ALL/balances

DO I have to deploy ontology-explorer to get the response i want?

laizy commented 4 years ago

https://github.com/ontio/ontology/pull/1279 this pr has added a jsonrpc api to query oep4 token balance.