ethereum_util 1.5.2 copy "ethereum_util: ^1.5.2" to clipboard
ethereum_util: ^1.5.2 copied to clipboard

a collection of utility functions for Ethereum

Ethereum Util for Dart πŸ‘‹ #

pub package build status

A collection of utility functions for Ethereum and other blockchains, ported from JavaScript to Dart. This library is a work in progress and aims to provide a comprehensive set of tools for Dart developers working with Ethereum.

Features ✨ #

  • Sign EIP-1559 and legacy transactions
  • RLP encoding and decoding
  • Ethereum address and public key utilities
  • Hashing functions (keccak256, sha256)
  • Signature utilities (ecrecover, toRpcSig)
  • Typed data signing (EIP-712)
  • Support for other coins like Polkadot (DOT), Sui (SUI), and Ripple (XRP)

Installation πŸ“¦ #

Add this to your pubspec.yaml:

dependencies:
  ethereum_util: ^1.5.1

Then run pub get or flutter pub get.

Usage πŸš€ #

Sign an EIP-1559 Transaction #

import 'dart:typed_data';
import 'package:convert/convert.dart';
import 'package:ethereum_util/src/eip1559Transaction.dart';

void main() {
  final txData = TxData(
    nonce: 1,
    maxPriorityFeePerGas: 10000,
    maxFeePerGas: 1000000,
    gasLimit: 21000,
    to: '0xfd79200d598a5a875ea30f0b4172aa525caaba53',
    value: 1000000000,
  );

  // Match the network. e.g. Mainnet: 1, Ropsten: 3.
  final txNetwork = TxNetwork(chainId: 3);

  final tx = Eip1559Transaction(txData, txNetwork);

  // Sign with your private key.
  // final privateKey = ...;
  // final result = tx.sign(privateKey);
  // print(hex.encode(result));
}

Sign a Legacy Transaction #

import 'dart:typed_data';
import 'package:ethereum_util/src/legacyTransaction.dart';

void main() {
  final txData = TxData(
    nonce: 46,
    gasPrice: 5000000000,
    gasLimit: 21000,
    to: '0x7fD1aA2b64d8ACfC85be1eA2DaF535f8821D0B6a',
    value: 1000000000000000,
  );

  // Match the network. e.g. Mainnet: 1, Ropsten: 3, BSC: 56.
  final txNetwork = TxNetwork(chainId: 56);

  final tx = LegacyTransaction(txData, txNetwork);

  // Sign with your private key.
  // final privateKey = ...;
  // final result = tx.sign(Uint8List.fromList(privateKey));
}

For more examples, please check the test directory.

Testing πŸ§ͺ #

To run the tests for this package, use the following command:

dart test

Contributing 🀝 #

Contributions are welcome! Please feel free to open an issue or submit a pull request on our GitHub repository.

License πŸ“ #

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

3
likes
115
points
65
downloads

Publisher

unverified uploader

Weekly Downloads

a collection of utility functions for Ethereum

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

bip32, bip39, buffer, collection, convert, crypto, ed25519_hd_key, json_annotation, pinenacl, pointycastle, sr25519, ss58, substrate_bip39, xrp_dart

More

Packages that depend on ethereum_util