numairawan/eth-gas-tracker-php

Powerful PHP library to retrieve live Ethereum gas prices.

v2.0.0 2023-09-26 23:34 UTC

This package is auto-updated.

Last update: 2024-10-27 22:38:56 UTC


README

Eth Gas Tracker PHP

Total Downloads Latest Version License

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.

Features

  • 🚀 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.

Installation

To install the library, you can use Composer and run the following command:

composer require numairawan/eth-gas-tracker-php

Usage

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";

Utilities

// 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;

Contributing

Contributions are welcome! Feel free to fork the repository and submit pull requests as well.

License

This project is licensed under the MIT license.

Connect with Me

Feel free to reach out to me for any project-related queries or collaborations. I'm always happy to connect and discuss ideas!

Telegram WhatsApp