Skip to content

Instantly share code, notes, and snippets.

@togosh
togosh / sumTSharesForAddress.js
Created February 1, 2022 16:56
Get Sum of All TShares for an Address - Codeak HEX API
// https://codeakk.medium.com/hex-development-data-a1b1822446fa
// https://togosh.medium.com/hex-developer-guide-3b018a943a55
// Replace XXXX below with staker address
test();
async function test(){
var stakerAddress = "XXXX";
var { stakeTShares, stakedHEX, stakedCount } = await get_stakeStartData(stakerAddress);
console.log("Staked Tshares: " + stakeTShares);
@togosh
togosh / getGlobalInfoHEX.js
Last active November 21, 2022 19:27
Circulating & Staked HEX and Total Tshares from Etherscan API - https://etherscan.io/apis
// https://codeakk.medium.com/hex-development-data-a1b1822446fa
// https://togosh.medium.com/hex-developer-guide-3b018a943a55
// https://etherscan.io/apis
test();
async function test(){
var { circulatingHEX, stakedHEX, totalTshares, penaltiesHEX } = await getGlobalInfo();
console.log("Circulating Supply: " + Number(circulatingHEX).toLocaleString(undefined, {minimumFractionDigits:0, maximumFractionDigits:0}));
console.log("Staked Supply: " + Number(stakedHEX).toLocaleString(undefined, {minimumFractionDigits:0, maximumFractionDigits:0}));
@togosh
togosh / allStakeDataHEX.js
Created November 7, 2021 19:45
Get All Historical Stake Data of HEX - for Jose (hex_crypto_bull) - Outputs 3 CSV files
//"dependencies": {
// "fetch-retry": "^5.0.1",
// "node-fetch": "^3.0.0"
// }
// Get all historical stake data by HEX day
//// Created for Jose (https://www.reddit.com/user/hex_crypto_bull/)
//Three CSV tables:
//- issued_cds (stakeStarts) // Desired: hex_staked>0 and shares>0
@togosh
togosh / averagePayoutPerTshareHEXfast.js
Last active November 5, 2021 02:02
Average Payout per Tshare of HEX between Days - Codeak API - Fast
// https://codeakk.medium.com/hex-development-data-a1b1822446fa
// https://togosh.medium.com/hex-developer-guide-3b018a943a55
test()
async function test(){
var startDay = 700; // 2 or higher
var endDay = 702;
var data = await get_dailyDataUpdateData();
@togosh
togosh / ethereumPriceAndGasFees.js
Created November 3, 2021 07:46
Ethereum Price and Gas Fees
var priceURL = "https://api.etherscan.io/api?module=stats&action=ethprice&apikey=YourApiKeyToken"
var gasURL = "https://api.etherscan.io/api?module=gastracker&action=gasoracle&apikey=YourApiKeyToken";
test();
async function test(){
var price = await getEthereumPrice();
await sleep(5000);
@togosh
togosh / totalValueLockedHEX.js
Created October 28, 2021 17:39
Total Value Locked of HEX
// https://codeakk.medium.com/hex-development-data-a1b1822446fa
// https://togosh.medium.com/hex-developer-guide-3b018a943a55
// https://thegraph.com/legacy-explorer/subgraph/uniswap/uniswap-v2
// https://thegraph.com/legacy-explorer/subgraph/uniswap/uniswap-v3
// https://etherscan.io/apis
// NOTE: REPLACE XXXXXXXX with Etherscan API Key
test();
async function test(){
@togosh
togosh / currencyRateCalculatorHEX.js
Last active October 17, 2021 09:33
Currency Rate Calculator for HEX --- https://exchangeratesapi.io/
// https://exchangeratesapi.io/ - Replace XXXXXXXXXXXXX with API Key
//////////////////////////////////////////////////////////
// SERVER
const schedule = require('node-schedule');
io = require('socket.io')(httpServer)
var jobCurrencyRates = schedule.scheduleJob("0 */3 * * *", function() {
getCurrencyData();
@togosh
togosh / nodeFetchRetryJSON.js
Last active September 23, 2021 07:54
Node Fetch Retry for JSON APIs - https://github.com/jonbern/fetch-retry
// https://codeakk.medium.com/hex-development-data-a1b1822446fa
// https://togosh.medium.com/hex-developer-guide-3b018a943a55
// https://github.com/jonbern/fetch-retry
// https://github.com/node-fetch/node-fetch/blob/main/README.md#custom-highwatermark
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
var fetchRetry = require('fetch-retry')(fetch, {
retryOn: async function(attempt, error, response) {
if (attempt > 3) { return false; }
@togosh
togosh / liquidityOfHEXUniswapV2V3.js
Last active April 12, 2023 01:25
Liquidity of HEX, USDC, ETH, DAI trading pairs - Uniswap V2 & V3
// https://codeakk.medium.com/hex-development-data-a1b1822446fa
// https://togosh.medium.com/hex-developer-guide-3b018a943a55
// https://thegraph.com/legacy-explorer/subgraph/uniswap/uniswap-v2
// https://thegraph.com/legacy-explorer/subgraph/uniswap/uniswap-v3
test();
async function test(){
console.log("=== Uniswap V2");
var { liquidityUV2_HEXUSDC, liquidityUV2_USDC } = await getUniswapV2HEXUSDC_Polling(); await sleep(1000);
@togosh
togosh / currentDayHEX.js
Created September 23, 2021 03:40
Current Day of HEX
// https://codeakk.medium.com/hex-development-data-a1b1822446fa
// https://togosh.medium.com/hex-developer-guide-3b018a943a55
// https://etherscan.io/apis
test();
async function test(){
var currentDay = await getCurrentDay();
console.log("Current Day: " + Number(currentDay).toLocaleString(undefined, {minimumFractionDigits:0, maximumFractionDigits:0}));
}