Skip to content

Instantly share code, notes, and snippets.

@christroutner
Forked from danielhumgon/bcash-calls.js
Created October 17, 2021 13:19
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 christroutner/7691982a8bef3f9e98ac1ab53309481a to your computer and use it in GitHub Desktop.
Save christroutner/7691982a8bef3f9e98ac1ab53309481a 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