Last active
January 7, 2024 14:59
-
-
Save juanpabloaj/ecc4dd5da170224faa51d4c05072af7e to your computer and use it in GitHub Desktop.
ethereum gas telegram alert
This file contains 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
#!/bin/bash | |
# get channel id | |
# https://api.telegram.org/bot<YourBOTToken>/getUpdates | |
# crontab | |
# */5 * * * bash /path/gas_alert.sh 2>&1 | logger -t gas_alert | |
cheapPrice="80" | |
url="https://api.etherscan.io/api?module=gastracker&action=gasoracle" | |
tempFile="/tmp/gas_alert_last_notification_time.txt" | |
price=$(curl $url | jq '.result.SafeGasPrice | tonumber' ) | |
function isOneHourPassed { | |
local lastNotificationTime=$(cat "$tempFile" 2> /dev/null) | |
local currentTime=$(date +%s) | |
if [ -z "$lastNotificationTime" ]; then | |
echo "true" | |
return | |
fi | |
local diff=$(($currentTime - $lastNotificationTime)) | |
local oneHour=3600 | |
if [ "$diff" -gt "$oneHour" ]; then | |
echo "true" | |
else | |
echo "false" | |
fi | |
} | |
if [ "$price" -lt "$cheapPrice" ] && [[ $(isOneHourPassed) == "true" ]] ; then | |
curl -v "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendMessage?chat_id=$TELEGRAM_CHANNEL_ID&text=ETH%20gas%20price%20${price}" | |
date +%s > "$tempFile" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment