Skip to content

Instantly share code, notes, and snippets.

@WietseWind
Created March 20, 2023 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WietseWind/07d0ab5f500783b1c9f63165c3b2bb68 to your computer and use it in GitHub Desktop.
Save WietseWind/07d0ab5f500783b1c9f63165c3b2bb68 to your computer and use it in GitHub Desktop.
Async/Sync check accounts for balance & TrustLine balance
import { XrplClient } from 'xrpl-client'
const account = 'rpKJsRsvKXt5JwV2PFRnvfkEH47MEWpVYo'
const client = new XrplClient()
let marker
let pages = 0
let accounts = 0
while ((typeof marker === 'undefined' && pages === 0) || marker) {
pages++
const txs = await client.send({ command: 'account_tx', account, limit: 10, marker })
marker = txs?.marker
const activatedAccounts = (txs.transactions || [])
.filter(transaction => transaction.tx?.Destination && transaction.tx.Destination !== account)
.map(transaction => Promise.all([
client.send({ command: 'account_info', account: transaction.tx.Destination }),
client.send({ command: 'account_lines', account: transaction.tx.Destination }),
]))
for await (const [acc, acclines] of activatedAccounts) {
console.log([
' ',
acc.account_data?.Account,
' '.repeat(39 - acc.account_data?.Account.length),
Number(acc.account_data?.Balance) / 1000,
' ',
acclines.lines?.[0]?.currency,
' ',
Math.round(Number(acclines.lines?.[0]?.balance) * 100) / 100,
].join(''))
accounts++
}
}
client.close()
console.log({
pages,
accounts,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment