4

I have an issuer account I1 and a distributor account D1. I have added trust of an asset DummyAsset issued by I1 with trust limit of 5000 DummyAsset.

How can I later verify/check the trust limit of a particular asset programmatically?

1 Answer 1

5

Horizon /account/{account} endpoint returns current balances, including trust limit for each asset in the list.

Each balance record looks like the following:

{
  "balance": "126.8107491",
  "limit": "5000.0000000",
  "asset_type": "credit_alphanum4",
  "asset_code": "BAR",
  "asset_issuer": "GBAUUA74H4XOQYRSOW2RZUA4QL5PB37U3JS5NE3RTB2ELJVMIF5RLMAG"
}

In order to retrieve the limit for the specified balance you need to load an account and enumerate through balance entries to find your asset. Check this sample code (JS):

server.accounts()
  .accountId('GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ')
  .call()
  .then(account => account.balances.filter(balanceRecord => balanceRecord.asset_code === 'BAR' && 
    balanceRecord.asset_issuer === 'GBAUUA74H4XOQYRSOW2RZUA4QL5PB37U3JS5NE3RTB2ELJVMIF5RLMAG')[0])
  .then(balanceRecord => {
    if (!balanceRecord) return Promise.reject('Trustline does not exist.')
    Promise.resolve(balanceRecord.limit)
  })
  .catch(err => console.error(err))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.