Skip to content

Instantly share code, notes, and snippets.

@shesek
Last active February 18, 2019 10:40
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 shesek/0b4581798890e7280d4de501d7ec76e3 to your computer and use it in GitHub Desktop.
Save shesek/0b4581798890e7280d4de501d7ec76e3 to your computer and use it in GitHub Desktop.
Bitcoin address UTXO extractor based on Blockstream's API
.container.py-5
h2 Bitcoin address UTXO query
form.mt-3
.form-group
label(for='address') Bitcoin address
input.form-control#address(type='text', name='address')
input.btn.btn-primary(type='submit', value='Get UTXOs')
table.table.mt-5
thead: tr #[th txid:vout] #[th value] #[th block height] #[th block time]
tbody
div.csv.mt-5
h4 CSV
p Format: #[em txid,vout,satoshis,block_height]
textarea.form-control(rows=6)
$('form').submit(e => {
e.preventDefault()
const address = $(e.target).find('[name=address]').val()
fetch(`https://blockstream.info/api/address/${address}/utxo`)
.then(r => r.json())
.then(utxos => {
$('tbody').empty().append(utxos.map(utxo => `
<tr>
<td>${utxo.txid}:${utxo.vout}</td>
<td>${+utxo.value/100000000}</td>
<td>${utxo.status.confirmed ? '#'+utxo.status.block_height : 'unconfirmed'}</td>
<td>${utxo.status.confirmed ? new Date(utxo.status.block_time*1000).toLocaleString() : ''}</td>
</tr>
`))
$('textarea').val(utxos.map(utxo => [utxo.txid, utxo.vout, utxo.value, utxo.status.block_height || '-1'].join(',')).join("\n"))
$('table,.csv').show()
})
.catch(console.error)
})
table, .csv { display: none }
@shesek
Copy link
Author

shesek commented Feb 17, 2019

@shesek
Copy link
Author

shesek commented Feb 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment