web3dart_get_fee_data 1.1.0 copy "web3dart_get_fee_data: ^1.1.0" to clipboard
web3dart_get_fee_data: ^1.1.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 Dart package for retrieving Ethereum fee data with full EIP-1559 support. Provides an API similar to ethers.js getFeeData().

pub package License: MIT

Features #

  • EIP-1559 Support: Get maxFeePerGas and maxPriorityFeePerGas for modern transactions
  • Legacy Compatibility: Automatic fallback to gasPrice for older networks
  • Custom Error Handling: Optional onError callback for custom fallback strategies

Installation #

Add this package to your pubspec.yaml:

dependencies:
  web3dart_get_fee_data: ^1.1.0

Then run:

dart pub get

Usage #

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

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

  try {
    final feeData = await getFeeData(ethClient);

    if (feeData.maxFeePerGas != null) {
      print('EIP-1559: ${feeData.maxFeePerGas} wei');
    } else {
      print('Legacy: ${feeData.gasPrice} wei');
    }
  } finally {
    ethClient.dispose();
    httpClient.close();
  }
}

Advanced Usage #

Custom Error Handling #

Use the onError callback for custom fallback strategies:

final feeData = await getFeeData(
  client,
  onError: (context) {
    print('Error in ${context.operation}: ${context.error}');
    print('Stack trace: ${context.stackTrace}');
    
    // Custom fallback strategies
    if (context.operation == 'eth_maxPriorityFeePerGas') {
      // Use zero priority fee for networks like Arbitrum
      return BigInt.zero;
    }
    
    // Use default fallback
    return context.fallbackValue;
  }
);

API Reference #

getFeeData(Web3Client client, {onError}) #

Parameters:

  • client: A connected Web3Client instance
  • onError: Optional callback for custom error handling

Returns: Future<FeeData> with current network fees

Example:

Future<FeeData> getFeeData(
  Web3Client client, {
  BigInt? Function(ErrorContext context)? onError,
})

FeeData #

Property Type Description
gasPrice BigInt? Legacy gas price in wei (always provided)
maxFeePerGas BigInt? EIP-1559 max fee per gas (when supported)
maxPriorityFeePerGas BigInt? EIP-1559 priority fee (when supported)

ErrorContext #

Provides comprehensive error information to onError callbacks:

Property Type Description
operation String The operation that failed (e.g., 'eth_maxPriorityFeePerGas')
error dynamic The original error that occurred
stackTrace StackTrace Stack trace when the error occurred
fallbackValue BigInt? Default fallback value that would be used
gasPrice BigInt Current gas price in wei
baseFeePerGas BigInt? Current base fee per gas in wei (EIP-1559 networks)

License #

MIT License - see LICENSE file.

0
likes
150
points
33
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

Documentation

API reference

License

MIT (license)

Dependencies

http, wallet, web3dart

More

Packages that depend on web3dart_get_fee_data