Last active
December 19, 2023 08:11
-
-
Save shesek/f0f73fb74b0083c46cf625570536e7aa to your computer and use it in GitHub Desktop.
Bitcoin address UTXO extractor based on Blockstream's API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<title>Bitcoin address UTXO extractor</title> | |
<style> | |
table, .csv { display: none } | |
</style> | |
<div class="container py-5"> | |
<h2>Bitcoin address UTXO query</h2> | |
<form class="mt-3"> | |
<div class="form-group"> | |
<label for="address">Bitcoin address</label> | |
<input class="form-control" id="address" type="text" name="address"> | |
</div> | |
<input class="btn btn-primary" type="submit" value="Get UTXOs"> | |
</form> | |
<table class="table mt-5"> | |
<thead> | |
<tr> | |
<th></th> | |
<th>txid:vout</th> | |
<th>value</th> | |
<th>block height</th> | |
<th>block time</th> | |
</tr> | |
</thead> | |
<tbody></tbody> | |
</table> | |
<div class="csv mt-5"> | |
<h4>CSV</h4> | |
<p>Format: <em>txid,vout,satoshis,block_height</em></p> | |
<textarea class="form-control" rows="6"></textarea> | |
</div> | |
</div> | |
<script> | |
document.querySelector('form').addEventListener('submit', e => { | |
e.preventDefault() | |
const address = e.target.querySelector('[name=address]').value | |
fetch(`https://blockstream.info/api/address/${address}/utxo`) | |
.then(r => r.json()) | |
.then(utxos => { | |
document.querySelector('tbody').innerHTML = utxos.map(utxo => ` | |
<tr> | |
<td><a href="https://blockstream.info/api/tx/${utxo.txid}/hex" target="_blank">rawtx</a></td> | |
<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> | |
`).join('') | |
document.querySelector('textarea').value = utxos.map(utxo => [utxo.txid, utxo.vout, utxo.value, utxo.status.block_height || '-1'].join(',')).join("\n") | |
document.querySelector('table').style.display = document.querySelector('.csv').style.display = 'block' | |
}) | |
.catch(console.error) | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment