PKTMonitor
by 3rror404
HTML
<input id="txtAddress" type="text" placeholder="Wallet" value="pkt1qcepy9745nhkc48hxazzsu80v4kxadchzfa7eq5">
<button id="btnFetchIncome" type="button">
Fetch Income
</button>
<button id="btnFetchCoins" type="button">
Fetch Coins
</button>
<button id="btnFetchLatestBlock" type="button">
Fetch Block
</button>
JavaScript
const txtAddress = document.querySelector('#txtAddress');
const btnFetchIncome = document.querySelector('#btnFetchIncome');
const btnFetchCoins = document.querySelector('#btnFetchCoins');
const btnFetchLatestBlock = document.querySelector('#btnFetchLatestBlock');
const TOKEN_DIVISIONS = 1073741824;
const ADDRESSES = ['pkt1qcepy9745nhkc48hxazzsu80v4kxadchzfa7eq5', 'pkt1qkk458e0x7rreulumlnee9uqm5e0pewzyupw348',
'pkt1qsmd2qelhpjwu9yjam2z6de3wptvktnh398r3xp', 'pkt1qr4n5lltnjemc47ghfmph2fnhxq0g5dm6dx0zwn',
'pkt1qvaefk7stfdgvr3nnsam57nscc9ccu72ttsz4px', 'pkt1qkrzn3frkuaw6j8ypqkpexxlcg0w3h53jauthup'];
let lastBlockHeightChecked = 0;
btnFetchIncome.addEventListener('click', fetchIncome);
btnFetchCoins.addEventListener('click', fetchCoins);
btnFetchLatestBlock.addEventListener('click', fetchLatestBlock);
function fetchIncome() {
const address = txtAddress.value;
//const url =
fetch(`https://pkt.cash/api/v1/PKT/pkt/address/${address}/income/2021-04-26/2021-04-27?mining=include`)
.then(response => response.json())
.then(data => console.log(data));
}
function fetchCoins() {
const address = txtAddress.value;
fetch(`https://pkt.cash/api/v1/PKT/pkt/address/${address}/coins/50/1?mining=only`)
.then(response => response.json())
.then(data => console.log(data));
}
function fetchRecentBlocks() {
}
function fetchLatestBlock() {
console.log('fetchLatestBlock()');
return fetch(`https://pkt.cash/api/v1/PKT/pkt/chain/down/1`)
.then(response => response.json())
.then(data => {
console.log(data);
if (data.results[0].height > lastBlockHeightChecked) {
console.warn(`🧊 Found block ${data.results[0].height} https://explorer.pkt.cash/block/${data.results[0].hash}`);
lastBlockHeightChecked = data.results[0].height;
return data;
}
return Promise.reject(`🧊 Already checked block ${data.results[0].height} https://explorer.pkt.cash/block/${data.results[0].hash}`);
...