web3dart_get_fee_data 1.0.0 copy "web3dart_get_fee_data: ^1.0.0" to clipboard
web3dart_get_fee_data: ^1.0.0 copied to clipboard

A Dart package for getting Ethereum fee data, including support for EIP-1559 transactions. Provides an easy-to-use API similar to ethers.js getFeeData().

web3dart_get_fee_data #

A comprehensive Dart package for retrieving Ethereum fee data, including full support for EIP-1559 transactions. This package provides an easy-to-use API that mirrors ethers.js getFeeData() functionality.

pub package License: MIT

Features #

  • EIP-1559 Support: Get maxFeePerGas and maxPriorityFeePerGas for modern transactions
  • Legacy Compatibility: Automatic fallback to traditional gasPrice for older networks
  • Network Detection: Seamlessly handles both EIP-1559 and legacy Ethereum networks
  • ethers.js Compatible: API designed to match ethers.js behavior for easy migration
  • Comprehensive Testing: Well-tested with real network integration tests
  • Type Safe: Full Dart type safety with nullable types for optional fee parameters

Installation #

Add this package to your pubspec.yaml:

dependencies:
  web3dart_get_fee_data: ^1.0.0

Then run:

dart pub get

Quick Start #

import 'package:web3dart/web3dart.dart';
import 'package:web3dart_get_fee_data/web3dart_get_fee_data.dart';
import 'package:http/http.dart';

void main() async {
  // Create Web3Client instance
  final httpClient = Client();
  final ethClient = Web3Client('https://eth.llamarpc.com', httpClient);

  try {
    // Get current fee data
    final feeData = await getFeeData(ethClient);

    // Check if network supports EIP-1559
    if (feeData.maxFeePerGas != null) {
      print('✅ EIP-1559 Network Detected');
      print('Max Fee Per Gas: ${feeData.maxFeePerGas} wei');
      print('Max Priority Fee: ${feeData.maxPriorityFeePerGas} wei');
    } else {
      print('📜 Legacy Network - Using Gas Price');
      print('Gas Price: ${feeData.gasPrice} wei');
    }
  } catch (e) {
    print('❌ Error: $e');
  } finally {
    ethClient.dispose();
  }
}

Usage Examples #

Basic Fee Data Retrieval #

import 'package:web3dart_get_fee_data/web3dart_get_fee_data.dart';

final feeData = await getFeeData(ethClient);
print('Current fee data: $feeData');

EIP-1559 Transaction Estimation #

final feeData = await getFeeData(ethClient);

if (feeData.maxFeePerGas != null && feeData.maxPriorityFeePerGas != null) {
  // Use EIP-1559 transaction
  final transaction = Transaction.callContract(
    contract: deployedContract,
    function: function,
    parameters: parameters,
    maxFeePerGas: EtherAmount.fromBigInt(EtherUnit.wei, feeData.maxFeePerGas!),
    maxPriorityFeePerGas: EtherAmount.fromBigInt(EtherUnit.wei, feeData.maxPriorityFeePerGas!),
  );
} else {
  // Fallback to legacy transaction
  final transaction = Transaction.callContract(
    contract: deployedContract,
    function: function,
    parameters: parameters,
    gasPrice: EtherAmount.fromBigInt(EtherUnit.wei, feeData.gasPrice!),
  );
}

API Reference #

getFeeData(Web3Client client) #

Retrieves current fee data from an Ethereum network.

Parameters:

  • client - A connected Web3Client instance

Returns:

  • Future<FeeData> - Fee data object containing current network fees

FeeData Class #

Represents Ethereum fee data for both legacy and EIP-1559 transactions.

Properties:

Property Type Description
gasPrice BigInt? Legacy gas price in wei (always provided)
maxFeePerGas BigInt? Maximum fee per gas for EIP-1559 (null for legacy networks)
maxPriorityFeePerGas BigInt? Maximum priority fee per gas for EIP-1559 (null for legacy networks)

EIP-1559 vs Legacy Networks #

EIP-1559 Networks #

For networks supporting EIP-1559, you'll receive:

  • gasPrice - Current gas price (for compatibility)
  • maxFeePerGas - Calculated as 2 * baseFee + priorityFee
  • maxPriorityFeePerGas - Current priority fee suggestion

Legacy Networks #

For older networks, you'll receive:

  • gasPrice - Current gas price
  • maxFeePerGas - null
  • maxPriorityFeePerGas - null

Testing #

Run the test suite:

dart test

The tests include:

  • ✅ Real network integration tests
  • ✅ Error handling verification
  • ✅ Data validation checks
  • ✅ EIP-1559 and legacy network compatibility

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Development Setup #

  1. Clone the repository
  2. Run dart pub get
  3. Make your changes
  4. Run dart test to ensure tests pass
  5. Submit a pull request

License #

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog #

See CHANGELOG.md for a detailed list of changes and version history.

Support #

0
likes
0
points
35
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart package for getting Ethereum fee data, including support for EIP-1559 transactions. Provides an easy-to-use API similar to ethers.js getFeeData().

Repository (GitHub)
View/report issues

Topics

#ethereum #web3 #blockchain #gas #eip-1559

License

unknown (license)

Dependencies

http, wallet, web3dart

More

Packages that depend on web3dart_get_fee_data