eth-gas-tracker-php is a powerful PHP library that provides developers with an effortless way to retrieve live Ethereum gas prices, empowering them to optimize transactions and smart contracts on the Ethereum network.
- π Retrieve live Ethereum gas prices with ease.
- β½οΈ Obtain up-to-date and accurate gas price data.
- πͺ Fine-tune transaction optimization based on real-time gas prices.
- π€ Seamless integration into existing PHP projects.
- π Comprehensive documentation and code examples for easy implementation.
To install the library, you can use Composer and run the following command:
composer require numairawan/eth-gas-tracker-php
To retrieve live Ethereum gas prices, follow these simple steps:
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;
Contributions are welcome! Feel free to fork the repository and submit pull requests as well.
This project is licensed under the MIT license.
Feel free to reach out to me for any project-related queries or collaborations. I'm always happy to connect and discuss ideas!