autoFill method

Future<void> autoFill(
  1. EVMRPC rpc, [
  2. EIP1559FeeRate feeRate = EIP1559FeeRate.normal
])

Automatically fills in transaction details, such as type, nonce, gas limit, and fees.

Determines the transaction type based on pending block information, fetches the nonce, gas limit, and calculates fees if required, updating the transaction accordingly.

Implementation

Future<void> autoFill(EVMRPC rpc,
    [EIP1559FeeRate feeRate = EIP1559FeeRate.normal]) async {
  if (_type == null) {
    final historical = await rpc.request(RPCGetFeeHistory(
        blockCount: 20,
        newestBlock: BlockTagOrNumber.latest,
        rewardPercentiles: [25, 60, 90]));
    if (historical != null) {
      _type = ETHTransactionType.eip1559;
    } else {
      _type = ETHTransactionType.legacy;
    }
  }
  _nonce ??= await rpc.request(RPCGetTransactionCount(address: from.address));
  _gasLimit ??= await rpc.request(RPCEstimateGas(
    transaction: _transaction.toEstimate(),
  ));
  if ((_isLegacy && _gasPrice == null) ||
      (!_isLegacy && _maxFeePerGas == null)) {
    await _calculateEIP1559Fee(rpc, feeRate);
  }
  _replaceTr();
}