Skip to content

Instantly share code, notes, and snippets.

@togosh
Created September 23, 2021 03:40
Show Gist options
  • Save togosh/169743c14a0d33e6abe5afcb004d0d0b to your computer and use it in GitHub Desktop.
Save togosh/169743c14a0d33e6abe5afcb004d0d0b to your computer and use it in GitHub Desktop.
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}));
}
async function getCurrentDay(){
const HEX_CONTRACT_ADDRESS = "0x2b591e99afe9f32eaa6214f7b7629768c40eeb39";
const HEX_CONTRACT_CURRENTDAY = "0x5c9302c9";
const ETHERSCAN_APIKEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
var etherScanURL =
"https://api.etherscan.io/api?" +
"module=proxy&action=eth_call" +
"&to=" + HEX_CONTRACT_ADDRESS +
"&data=" + HEX_CONTRACT_CURRENTDAY +
"&apikey=" + ETHERSCAN_APIKEY;
return await fetch(etherScanURL, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
.then(res => res.json())
.then(res => {
var currentDay = parseInt(res.result, 16);
return currentDay;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment