Created
January 9, 2023 21:01
-
-
Save azmenak/561cfdcdab34b65528b34ad4a5146c88 to your computer and use it in GitHub Desktop.
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 characters
const ethGasStationApiUrl = `https://api.etherscan.io/api?module=gastracker&action=gasoracle&apikey=`; | |
const req = new Request(ethGasStationApiUrl); | |
const res = await req.loadJSON(); | |
if (config.runsInWidget) { | |
const widget = new ListWidget(); | |
const textColor = Color.dynamic(Color.black(), Color.white()); | |
const title = widget.addText("Gas Prices"); | |
title.textColor = textColor; | |
title.textOpacity = 0.8; | |
title.font = new Font("Helvetica-Light ", 10); | |
widget.addSpacer(2); | |
const fastest = widget.addText(`Fast: ${res.result.FastGasPrice}`); | |
fastest.textColor = textColor; | |
fastest.font = new Font("Courier", 14); | |
widget.addSpacer(2); | |
const average = widget.addText(`Standard: ${res.result.SafeGasPrice}`); | |
average.textColor = textColor; | |
average.font = new Font("Courier", 14); | |
widget.addSpacer(2); | |
const next = widget.addText(`Next: ${Number.parseFloat(res.result.suggestBaseFee).toFixed(2)}`); | |
next.textColor = textColor; | |
next.font = new Font("Courier", 14); | |
widget.addSpacer(2); | |
const date = new Date(); | |
const minutes = date.getMinutes(); | |
const formattedMinutes = minutes < 10 ? `0${minutes}` : minutes.toString(); | |
const lastUpdate = widget.addText(`Last Update: ${date.getHours()}:${formattedMinutes}`); | |
lastUpdate.textColor = textColor; | |
title.textOpacity = 0.8; | |
lastUpdate.font = new Font("Helvetica-Light", 10); | |
Script.setWidget(widget); | |
Script.complete(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment