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

a collection of utility functions for Ethereum

ethereum_util #

This project is a work in progress.

Porting Ethereum utilities from Javascript to Dart:

Check test folder for usage.


Sign EIP 1559 transaction #

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

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

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

  var tx = new Eip1559Transaction(txData, txNetwork);
  // var data = tx.getMessageToSign();
  // print(hex.encode(data));

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

Sign legacy transaction #

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

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

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

  var tx = new LegacyTransaction(txData, txNetwork);
  var data = tx.serialize();

  // Sign with your private key.
  var result = tx.sign(Uint8List.fromList(privateKey));
}
3
likes
0
points
70
downloads

Publisher

unverified uploader

Weekly Downloads

a collection of utility functions for Ethereum

Repository (GitHub)
View/report issues

License

unknown (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