Skip to content

Instantly share code, notes, and snippets.

@danielhumgon
Created October 13, 2021 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danielhumgon/ba996fdbb2addcefbc61f742b59b24bd to your computer and use it in GitHub Desktop.
Save danielhumgon/ba996fdbb2addcefbc61f742b59b24bd to your computer and use it in GitHub Desktop.
JS code example for querying the SLP balance of an address.
const axios = require('axios').default
const bchAddress = 'bitcoincash:qpnty9t0w93fez04h7yzevujpv8pun204qv6yfuahk'
const SERVER = process.env.SERVER
// Get SLP balance of an address
const slpBalances = async (address) => {
try {
if (!address || typeof address !== 'string') {
throw new Error('address must be string')
}
const options = {
method: 'GET',
url: `${SERVER}coin/address/${address}?slp=true`
}
// Get UTXOs of an address
const result = await axios(options)
const utxos = result.data
console.log(`UTXOS : ${utxos.length}`)
// Filter SLP UTXOs
const slpUtxos = utxos.filter((val) => val.slp)
console.log(`slpUtxos : ${slpUtxos.length}`)
console.log(slpUtxos)
return slpUtxos
} catch (error) {
console.log(error)
throw error
}
}
slpBalances(bchAddress)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment