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:
- Gas Predictions — Current suggested amount & wait time
- 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
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!
Let’s build a gas station in two easy steps:
1. Call the first endpoint: Gas Predictions
2. Call the second endpoint: Gas Percentiles
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!!
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!