Skip to content

Instantly share code, notes, and snippets.

@ktalebian
Created February 24, 2022 04:32
Show Gist options
  • Save ktalebian/d9d87cf35440f0ecfeb3ea5b58dd055e to your computer and use it in GitHub Desktop.
Save ktalebian/d9d87cf35440f0ecfeb3ea5b58dd055e to your computer and use it in GitHub Desktop.
Find out which coin is the fastest to reach minimum payout requirement
const https = require('https');
// Usage: node unmineable-fastest.js 26
// Where the first argument is your GPU's hashrate in MH/s
/**
* onResponse handler for https request
*/
const onResponse = (resolve) => (res) => {
const data = [];
res.on('data', (chunk) => data.push(chunk));
res.on('end', () => resolve(JSON.parse(Buffer.concat(data).toString())));
}
/**
* Gets the list of coins
*/
const listCoins = async () => {
return new Promise((resolve, reject) => {
const options = {
method: 'GET',
hostname: 'api.unminable.com',
port: 443,
path: '/v4/coin',
};
const req = https.request(options, onResponse((resp) => resolve(resp.data)));
req.on('error', reject);
req.end();
});
}
/**
* Returns the stats about a coin
*/
const getCoin = async (token) => {
return new Promise((resolve, reject) => {
const options = {
method: 'GET',
hostname: 'api.unminable.com',
protocol: 'https:',
path: `/v3/coins/${token}`,
};
const req = https.request(options, onResponse((resp) => resolve(resp.coin)));
req.on('error', reject);
req.end();
});
}
/**
* Gets the rewards
* @param coin
* @param mh
* @return {Promise<unknown>}
*/
const getRewards = async (coin, mh) => {
return new Promise((resolve, reject) => {
const data = JSON.stringify({
algo: 'ethash',
coin,
mh,
});
const options = {
method: 'POST',
hostname: 'api.unminable.com',
port: 443,
path: '/v3/calculate/reward',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length,
},
};
const req = https.request(options, onResponse(resolve));
req.on('error', reject)
req.write(data)
req.end();
});
}
/**
* Finds the fastest coin to cash out
*/
const start = async (argv) => {
const hashRate = parseFloat(argv[0]);
if (!Number.isFinite(hashRate)) {
console.error(`HashRate ${hashRate} is not valid`);
process.exit(1);
}
const coins = await listCoins();
const result = [];
for (const coin of coins) {
console.log('Processing', coin.symbol);
const info = await getCoin(coin.symbol);
const rewards = await getRewards(coin.symbol, hashRate);
if (info.payment_threshold && rewards.per_day) {
result.push({ coin, rewards, info, daysToVest: info.payment_threshold/rewards.per_day });
}
}
return result
.sort((a, b) => a.daysToVest < b.daysToVest ? -1 : 1)
.map(a => ({symbol: a.coin.symbol, daysToVest: a.daysToVest }));
}
start(process.argv.splice(2)).then(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment