forked from OutCast3k/coinbin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutxo_tool.html
More file actions
70 lines (59 loc) · 2.16 KB
/
utxo_tool.html
File metadata and controls
70 lines (59 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>UTXO Fetcher</title>
<style>
body { font-family: Arial, sans-serif; margin: 2rem; background-color: #f9f9f9; }
input[type="text"] { width: 400px; padding: 0.5rem; }
button { padding: 0.5rem 1rem; margin-left: 0.5rem; }
.utxo { border: 1px solid #ddd; padding: 1rem; margin: 1rem 0; background-color: #fff; }
.error { color: red; }
</style>
</head>
<body>
<h2>Bitcoin UTXO Fetcher</h2>
<p>Enter a Bitcoin address to list unspent outputs (UTXOs):</p>
<input type="text" id="addressInput" placeholder="Enter Bitcoin address">
<button onclick="fetchUTXOs()">Get UTXOs</button>
<div id="results"></div>
<script>
async function fetchUTXOs() {
const address = document.getElementById('addressInput').value.trim();
const resultsDiv = document.getElementById('results');
resultsDiv.innerHTML = '';
if (!address) {
resultsDiv.innerHTML = '<p class="error">Please enter a Bitcoin address.</p>';
return;
}
const apiUrl = `https://blockstream.info/api/address/${address}/utxo`;
try {
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error(`HTTP error ${response.status}`);
}
const utxos = await response.json();
if (utxos.length === 0) {
resultsDiv.innerHTML = `<p>No UTXOs found for address: ${address}</p>`;
return;
}
utxos.forEach((utxo, i) => {
const div = document.createElement('div');
div.className = 'utxo';
div.innerHTML = `
<strong>UTXO #${i + 1}</strong><br>
<b>TXID:</b> ${utxo.txid}<br>
<b>VOUT (index):</b> ${utxo.vout}<br>
<b>Amount (sats):</b> ${utxo.value}<br>
<b>Status:</b> ${utxo.status.confirmed ? "Confirmed" : "Unconfirmed"}<br>
<b>Block Height:</b> ${utxo.status.block_height || "N/A"}
`;
resultsDiv.appendChild(div);
});
} catch (err) {
resultsDiv.innerHTML = `<p class="error">Failed to fetch UTXOs: ${err.message}</p>`;
}
}
</script>
</body>
</html>