Ethereum Transaction Fee Calculator

I wrote a simple calculator for checking current Ethereum transaction fees. All this information is also easily obtained via ETH gas station. However, I sometimes find it more convenient to work in the terminal without needing to check in on a full browser.

Posting it here in case anyone might find it useful. Feel free to use it as is or make changes or whatever…

The script runs in a GNU/Linux bash shell. Required installed programs are:

  1. bc
  2. jq
  3. curl

Install prerequisites:

$ sudo apt install bc jq curl

Script:

#!/bin/bash
#
# This script requires two API keys.
# 1. API Key for Defi Pulse
#     https://data.defipulse.com/signup
#
# 2. API Key for Etherscan
#     https://etherscan.io/apis
#
# Once you obtain the API keys, simply enter them into the script and you'll be
#     able to track Ethereum gas prices in your terminal.
#
###############################################

defi_key="no_key"
etherscan_key="no_key"
gwei=0.000000001
transfer=21000
contract=250000
gas_price=$(curl -s -G -d "api-key=$defi_key" https://ethgasstation.info/api/ethgasAPI.json |jq .average)
eth_price=$(curl -s -d "module=stats" -d "action=ethprice" -d "apikey=$etherscan_key" https://api.etherscan.io/api |jq -r .result.ethusd)
gas_p=$(echo "scale=8;$gas_price/10" |bc)
simple=$(echo "scale=8;$eth_price*$gas_price/10*$gwei*$transfer" |bc)
complex=$(echo "scale=8;$eth_price*$gas_price/10*$gwei*$contract" |bc)
printf '\nEthereum Transaction Cost Estimator\n'
date
echo -e "-----------------------------------------\n"
printf 'Settings:\n\n'
printf 'Transfer Gas Limit:\t\t21,000\n'
printf 'Contract Gas Limit:\t\t250,000\n'
printf 'Current Average Gas Price:\t%4.1f gwei\n' $gas_p
printf 'Current ETH Value:\t\t$%4.2f\n' $eth_price
echo -e "-----------------------------------------\n"
printf 'Average Simple Transfer:\t$%1.3f\n' $simple
printf 'Average Contract:\t\t$%1.3f\n' $complex

Example Output:

$ gas

Ethereum Transaction Cost Estimator
Fri 10 Jul 2020 09:57:25 AM EDT
-----------------------------------------

Settings:

Transfer Gas Limit:	    	21,000
Contract Gas Limit:	    	250,000
Current Average Gas Price:	42.0 gwei
Current ETH Value:	    	$238.86
-----------------------------------------

Average Simple Transfer:	$0.211
Average Contract:	    	$2.508
7 Likes

thanks @beast this will be appreciated by lots of folks, I am sure! thank you for sharing