-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.request.bitcoin.js
36 lines (32 loc) · 1.08 KB
/
get.request.bitcoin.js
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
const axios = require('axios');
const baseUrl = "https://blockstream.info/testnet/api/"
// Bitcoin: https://blockstream.info/api/
// Bitcoin Testnet: https://blockstream.info/testnet/api/
async function checkBalance(address) {
try {
const response = await axios.get(`${baseUrl}/address/${address}/utxo`);
const utxos = response.data;
let balance = 0;
utxos.forEach(utxo => {
balance += utxo.value;
});
return balance / 100000000;
} catch (err) {
console.log("err:", err?.response?.data)
}
}
async function getLatestBlockNumber() {
try {
const response = await axios.get(`${baseUrl}/blocks/tip/height`);
return response.data;
} catch (err) {
console.log("err:", err?.response?.data)
}
}
async function checkDetails(){
let walletAddress = "Bitcoin wallet public key"
let balance = await checkBalance(walletAddress)
console.log(`Wallet address ${walletAddress} with balance: ${balance}`)
console.log(`latest block number: ${await getLatestBlockNumber()}`)
}
checkDetails()