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

A production-ready Dart wrapper for the Etherscan API V2, supporting 60+ EVM chains with a single API key. Features include rate limiting, caching, circuit breaker pattern, and type-safe models.

example/polybrainz_etherscan_example.dart

// ignore_for_file: avoid_print

import 'package:polybrainz_etherscan/polybrainz_etherscan.dart';

void main() async {
  // Create API instance with your API key
  final api = await EtherscanApi.create(apiKey: 'YOUR_API_KEY');

  // Example: Get ETH balance for Vitalik's address
  final address = EthereumAddress('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045');

  final result = await api.account.getBalance(address);

  result.when(
    success: (balance) {
      print('Address: ${address.hex}');
      print('Balance: ${balance.balanceInEther} ETH');
    },
    failure: (error) => print('Error: ${error.message}'),
  );

  // Example: Get gas prices
  final gasResult = await api.gas.getGasOracle();

  gasResult.when(
    success: (oracle) {
      print('\nCurrent Gas Prices:');
      print('Safe: ${oracle.safeGasPrice.toGwei} Gwei');
      print('Propose: ${oracle.proposeGasPrice.toGwei} Gwei');
      print('Fast: ${oracle.fastGasPrice.toGwei} Gwei');
    },
    failure: (error) => print('Error: ${error.message}'),
  );

  // Example: Use a different chain (Polygon)
  final polygonApi = api.forChain(Chain.polygon);

  final polygonResult = await polygonApi.account.getBalance(address);

  polygonResult.when(
    success: (balance) {
      print('\nPolygon Balance: ${balance.balanceInEther} MATIC');
    },
    failure: (error) => print('Polygon Error: ${error.message}'),
  );
}
0
likes
80
points
101
downloads

Publisher

verified publisherpolybrainz.bot

Weekly Downloads

A production-ready Dart wrapper for the Etherscan API V2, supporting 60+ EVM chains with a single API key. Features include rate limiting, caching, circuit breaker pattern, and type-safe models.

Repository (GitHub)
View/report issues

Topics

#ethereum #blockchain #etherscan #web3 #api

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

collection, crypto, dio, freezed_annotation, json_annotation

More

Packages that depend on polybrainz_etherscan