Skip to main content
Your application will be querying data from Horizon (one of Stellar’s APIs) throughout its functionality. Information such as account balances, transaction history, sequence numbers for transactions, asset availability, and more are stored in Horizon’s database. Here is a list of some common queries that you’ll make.
In other places in this tutorial, we have omitted the JSDoc descriptions and typing for the sake of clean presentation. Here, we’re including those to make these functions more copy/paste-able.

Imports and types

/src/lib/stellar/horizonQueries.js
Source: https://github.com/stellar/basic-payment-app/blob/main/src/lib/stellar/horizonQueries.js

fetchAccount

Gives an account’s sequence number, asset balances, and trustlines.
/src/lib/stellar/horizonQueries.js
Source: https://github.com/stellar/basic-payment-app/blob/main/src/lib/stellar/horizonQueries.js

fetchAccountBalances

Gets existing balances for a given publicKey.
/src/lib/stellar/horizonQueries.js
Source: https://github.com/stellar/basic-payment-app/blob/main/src/lib/stellar/horizonQueries.js

fetchRecentPayments

Finds any payments made to or from the given publicKey (includes: payments, path payments, and account merges).
/src/lib/stellar/horizonQueries.js
Source: https://github.com/stellar/basic-payment-app/blob/main/src/lib/stellar/horizonQueries.js

submit

Submit a signed transaction to the Stellar network.
/src/lib/stellar/horizonQueries.js
Source: https://github.com/stellar/basic-payment-app/blob/main/src/lib/stellar/horizonQueries.js

fetchAssetsWithHomeDomains

We create a brand new HomeDomainBalanceLine type that includes the balance information of a user’s trustline, and also adds the home_domain of the asset issuer. If you’re using something else for type safety (or nothing at all), feel free to adapt or ignore the @typedefs we’ve included here. Then, it looks at all the issuer accounts and returns only the ones with a home_domain set on the account.
/src/lib/stellar/horizonQueries.js
Source: https://github.com/stellar/basic-payment-app/blob/main/src/lib/stellar/horizonQueries.js

findStrictSendPaths

Find the available strict send paths between a source asset/amount and receiving account.
/src/lib/stellar/horizonQueries.js
Source: https://github.com/stellar/basic-payment-app/blob/main/src/lib/stellar/horizonQueries.js

findStrictReceivePaths

Find the available strict receive paths between a source account and receiving asset/amount.
/src/lib/stellar/horizonQueries.js
Source: https://github.com/stellar/basic-payment-app/blob/main/src/lib/stellar/horizonQueries.js

Query Stellar Expert

Stellar Expert is a third-party block explorer that is indispensable as a tool for understanding what is happening on the Stellar network. On our /dashboard/assets page, we’re pre-populating a list of asset trustlines a user might choose to add to their Stellar account. We get this list of assets from the Stellar Expert API.
Stellar Expert employs their own algorithm to determine the quality of an asset. This algorithm considers things like the number of payments made using an asset, the number of accounts holding that asset, how much of the asset is available on the DEX or in liquidity pools, and so on. These rankings aren’t a “final determination” of an asset’s quality by any means, and are more like an observation of which Stellar assets see the most use and activity on the network.
We’ve created our own RankedAsset type so BasicPay knows how to interact with these objects. And we are then retrieving the ten most highly-rated assets from the Stellar Expert API.
/src/lib/utils/stellarExpert.js
Source: https://github.com/stellar/basic-payment-app/blob/main/src/lib/utils/stellarExpert.js