Last active
December 5, 2024 16:41
-
-
Save iatomic1/8f58b201a73ffe574f9fc7ae5c79b4a5 to your computer and use it in GitHub Desktop.
Revisions
-
iatomic1 revised this gist
Dec 5, 2024 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -11,8 +11,11 @@ bot( if (!match) { return await message.send('Please provide a valid STX address.'); } const arr = match.split(" ") const stx_addr = arr[0] const limit = arr[1] const res = await fetch(`https://api.hiro.so/extended/v2/addresses/${stx_addr}/transactions?limit=${limit}&offset=0`); const json = await res.json(); const latestTxs = json.results; -
iatomic1 revised this gist
Dec 5, 2024 . 1 changed file with 10 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -19,10 +19,17 @@ bot( let output = ''; for (let i = 0; i < latestTxs.length; i++) { const tx = latestTxs[i]; output += `Transaction ${i + 1}: **Type:** ${tx.tx.tx_type}`; if (tx.tx.tx_type === 'token_transfer') { output += ` **Receiver:** ${tx.tx.token_transfer.recipient_address} **Sender:** ${tx.tx.sender_address}`; } output += ` **Stx Sent:** ${(tx.stx_sent / 1000000).toFixed(6)} **Stx Received:** ${(tx.stx_received / 1000000).toFixed(2)}\n`; } @@ -32,4 +39,4 @@ bot( return await message.send(error.message, { quoted: message.data }); } } ); -
iatomic1 revised this gist
Dec 5, 2024 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -20,16 +20,16 @@ bot( for (let i = 0; i < latestTxs.length; i++) { const tx = latestTxs[i]; output += `Transaction ${i + 1}: **Type:** ${tx.tx.tx_type} **Receiver:** ${tx.tx.token_transfer.recipient_address} **Sender:** ${tx.tx.sender_address} **Stx Sent:** ${(tx.stx_sent / 1000000).toFixed(6)} **Stx Received:** ${(tx.stx_received / 1000000).toFixed(2)}\n`; } await message.send(output.trim()); } catch (error) { return await message.send(error.message, { quoted: message.data }); } } ); -
iatomic1 revised this gist
Dec 5, 2024 . 1 changed file with 14 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ const { bot, forwardOrBroadCast } = require('../lib/'); bot( { pattern: 'transactions ?(.*)', desc: 'Gets latest 3 STX transactions for the provided address', type: 'all', }, async (message, match) => { @@ -12,18 +12,22 @@ bot( return await message.send('Please provide a valid STX address.'); } const res = await fetch(`https://api.hiro.so/extended/v2/addresses/${match}/transactions?limit=3&offset=0`); const json = await res.json(); const latestTxs = json.results; let output = ''; for (let i = 0; i < latestTxs.length; i++) { const tx = latestTxs[i]; output += `Transaction ${i + 1}: Type: ${tx.tx.tx_type} Receiver: ${tx.tx.token_transfer.recipient_address} Sender: ${tx.tx.sender_address} Stx Sent: ${(tx.stx_sent / 1000000).toFixed(6)} Stx Received: ${(tx.stx_received / 1000000).toFixed(2)}\n`; } await message.send(output.trim()); } catch (error) { return await message.send(error.message, { quoted: message.data }); } -
iatomic1 revised this gist
Dec 5, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ bot( return await message.send('Please provide a valid STX address.'); } const res = await fetch(`https://api.hiro.so/extended/v2/addresses/${match}/transactions?limit=1&offset=1`); const json = await res.json(); const [latestTx] = json.results; -
iatomic1 revised this gist
Dec 5, 2024 . 1 changed file with 15 additions and 46 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,60 +3,29 @@ const { bot, forwardOrBroadCast } = require('../lib/'); bot( { pattern: 'transactions ?(.*)', desc: 'Gets latest STX transaction for the provided address', type: 'all', }, async (message, match) => { try { if (!match) { return await message.send('Please provide a valid STX address.'); } const res = await fetch(`https://api.hiro.so/extended/v2/addresses/${match}/transactions?limit=1&offset=0`); const json = await res.json(); const [latestTx] = json.results; const output = `Latest Transaction: Type: ${latestTx.tx.tx_type} Receiver: ${latestTx.tx.token_transfer.recipient_address} Sender: ${latestTx.tx.sender_address} Stx Sent: ${(latestTx.stx_sent / 1000000).toFixed(6)} Stx Received: ${(latestTx.stx_received / 1000000).toFixed(2)}`; await message.send(output); } catch (error) { return await message.send(error.message, { quoted: message.data }); } } ); -
iatomic1 created this gist
Dec 4, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ const { bot, forwardOrBroadCast } = require('../lib/'); bot( { pattern: 'transactions ?(.*)', desc: 'Gets STX balance of the address the command is replied to', type: 'all', }, async (message, match) => { try { if (!match) return await message.send('it is necessary to send an address!') const res = await fetch(`https://api.hiro.so/extended/v2/addresses/${match}/transactions?limit=1&offset=1`) const json = await res.json() const transactionsRes = json.results function createTransactionTable(transactions) { const headers = ["Type", "Receiver Address", "Sender Address", "Stx Sent", "Stx Received"]; const colWidths = headers.map((header, i) => Math.max( header.length, ...transactions.map(tx => { const values = [ tx.tx.tx_type, tx.tx.token_transfer.recipient_address, tx.tx.sender_address, tx.stx_sent, tx.stx_received ]; return String(values[i]).length; }) ) ); const formatRow = (row) => row.map((cell, i) => String(cell).padEnd(colWidths[i])).join(' | '); const headerRow = formatRow(headers); const separator = colWidths.map(width => '-'.repeat(width)).join('-+-'); const rows = transactions.map(tx => formatRow([ tx.tx.tx_type, tx.tx.token_transfer.recipient_address, tx.tx.sender_address, Number(tx.stx_sent) / 1000000, Number(tx.stx_received) / 1000000 ]) ); return [headerRow, separator, ...rows].join('\n'); } console.log(createTransactionTable(transactionsRes)); await message.send(createTransactionTable(transactionsRes)); } catch (error) { return await message.send(error.message, { quoted: message.data }); } } );