Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A scriptable Gas Price Widget
const ethGasStationApiUrl = `https://ethgasstation.info/api/ethgasAPI.json`;
const req = new Request(ethGasStationApiUrl);
const res = await req.loadJSON();
if (config.runsInWidget) {
const widget = new ListWidget();
const title = widget.addText("Gas Prices");
title.textColor = Color.white();
title.textOpacity = 0.8;
title.font = new Font("Helvetica-Light ", 10);
widget.addSpacer(2);
const fastestGas = (res.fastest/10);
const fastest = widget.addText(`Trader: ${fastestGas}`);
fastest.textColor = Color.white();
fastest.font = new Font("Courier", 14);
widget.addSpacer(2);
const fastGas = (res.fast/10);
const fast = widget.addText(`Fast: ${fastGas}`);
fast.textColor = Color.white();
fast.font = new Font("Courier", 14);
widget.addSpacer(2);
const averageGas = (res.average/10);
const average = widget.addText(`Standard: ${averageGas}`);
average.textColor = Color.white();
average.font = new Font("Courier", 14);
widget.addSpacer(2);
const date = new Date();
const lastUpdate = widget.addText(`LastUpdate: ${date.getHours()}:${date.getMinutes()}`);
lastUpdate.textColor = Color.white();
title.textOpacity = 0.8;
lastUpdate.font = new Font("Helvetica-Light", 10);
if (fastGas < 100) {
let n = new Notification()
n.title = "🤑 Gas cheap! Under 100"
// n.subtitle = ""
n.body = "Make yours swap baby"
n.sound = "alert"
n.schedule();
}
Script.setWidget(widget);
Script.complete();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment