PHP code example of numairawan / eth-gas-tracker-php
1. Go to this page and download the library: Download numairawan/eth-gas-tracker-php library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
numairawan / eth-gas-tracker-php example snippets
use NumairAwan\EthGasTracker\EthereumGasPrice;
// Instantiate the EthereumGasPrice
$ethereumGasPrice = new EthereumGasPrice();
// Get gas prices
$gasPrice = $ethereumGasPrice->getGasPrices();
// safe gas price
echo "Gas Prices:\n";
echo "Slow Gas Price: " . $gasPrice->proposeGas . " Gwei\n";
echo "Safe Gas Price: " . $gasPrice->safeGas . " Gwei\n";
echo "Fast Gas Price: " . $gasPrice->fastGas . " Gwei\n";
// Convert gas prices to Wei
$fastGasPriceWei = $ethereumGasPrice->toWei($gasPrice->fastGas);
echo "Fast Gas Price (Wei): " . $fastGasPriceWei . PHP_EOL;
// Convert gas prices (WEI) to Hexadecimal with '0x' prefix (don't pass second parameter to just get hex)
$fastGasPriceHex = $ethereumGasPrice->toHex($fastGasPriceWei, true);
echo "Fast Gas Price (Hex): " . $fastGasPriceHex . PHP_EOL;