Ethereum Gas Price & Predictions

Build an Ethereum gas station, using the Amberdata API! Reduce fees for your users, by utilizing gas prediction & percentiles.

TLDR; Most dApps are over pricing their transactions to keep confirmation time quick.


Tutorial: Get Gas Predictions & Percentiles

We’re going to build a simple gas station utilizing two data sets:

  1. Gas Predictions — Current suggested amount & wait time
  2. Gas Percentiles — Current depth of gas amounts by percentile

What is this used for?

  • dApps that set a gas price for transactions
  • Front runners that need to beat competition
  • Estimating or scheduling a transaction based on gas stats

If you aren’t sure what “Gas” is, there are a few great resources for understanding how it works.

The Gas Equation:

Gas Used * Gas Price = Fee

  • Gas: unit of measuring the computational work
  • Gas Price: amount of Ether you’re willing to pay for every unit of gas
  • Gas limit: maximum amount of gas you’re willing to spend on a particular transaction

Note: definitions sourced here

As you can see, knowing the best gas price will allow you to make smarter decisions, ultimately reducing fees for your users!

Tutorial: Overview

Let’s build a gas station in a few easy steps:
0. Get an Amberdata API key, to make calls to gas data endpoints
1. Call the first endpoint: Gas Predictions
2. Call the second endpoint: Gas Percentiles

Step 0: Get a Free Amberdata API Key

Go to Amberdata.io, and click “Get Started” to get a Free Developer API Key. You will need this to access the data in the next steps.

View Gas Predictions

Step 1: Get Gas Predictions

Using Axios & Amberdata API it is possible to get current gas predictions. See the following snippet:

The data is setup to deliver gas suggestions, blocks before confirmation and estimated wait time.

You can see we’ve implemented this here →

Step 2: Get Gas Percentiles

Now that you have the API setup, it’s easy to access gas percentiles.
See the following snippet:

Using percentile based data allows your dApp to keep fee estimation smart. Based on the current standings, you can look at which percentile is required to beat out majority of the competition. You no longer have to guess on the threshold needed to keep confirmation times fast, therefore saving your users precious Ether!!

There are other ways gas can be visualized as well, see here for a comprehensive look into gas & fees →


Fin

Now its your turn! Setup a smart gas station within your dApp! If you integrate, send us a link and we’ll showcase your integration!

This is just one of many ways to build using the Amberdata API. In the coming weeks we will be sharing more tutorials, stay tuned!