xclud / web3dart

Ethereum library, written in Dart.
https://pub.dev/packages/web3dart
MIT License
170 stars 94 forks source link

Added getGasEIP1559, feeHistory methods and Upgrade EtherAmount #65

Closed MahmoudKEA closed 1 year ago

MahmoudKEA commented 1 year ago

Get maxFeePerGas and maxPriorityFeePerGas using getGasInEIP1559 method

Web3Client web3 = Web3Client(network.rpc, httpClient);

Map<String, EIP1559Information> gasEIP = await web3.getGasInEIP1559();
// result: {'slow': EIP1559Information, 'medium': EIP1559Information, 'fast': EIP1559Information}

// Choose the speed rate you want, for example (medium)
EIP1559Information gasEIPInfo = gasEIP['medium']!;

// Finally, set the gas fee of your choice
Transaction tx = Transaction(
  maxPriorityFeePerGas: gasEIPInfo.maxPriorityFeePerGas,
  maxFeePerGas: gasEIPInfo.maxFeePerGas,
);

Get fee history from some blocks

// Count of blocks
int historicalBlocks = 10;

Map<String, dynamic> feeHistory = await web3.getFeeHistory(
  historicalBlocks,
  atBlock: BlockNum.pending(),
  rewardPercentiles: [25, 50, 75], // percentage of fill
);

EtherAmount able to get value by decimals ( To handle different decimals of tokens ) EtherAmount acceptable datatypes of string, int, double or BigInt

int tokenDecimals = 9;

EtherAmount amount = EtherAmount.fromUnitAndValue(
  EtherAmount.getUintDecimals(tokenDecimals),
  100.65658,
);

// Get value in decimals
amount.getValueInDecimals(tokenDecimals)
// result: 100.65658
juampiq6 commented 1 year ago

nice work, i left you some comments to review

xclud commented 1 year ago

This is done in https://pub.dev/packages/eip1559.