RawEVMTransactionType1.fromUnsignedHexing constructor

RawEVMTransactionType1.fromUnsignedHexing(
  1. String rawTxHex
)

Implementation

factory RawEVMTransactionType1.fromUnsignedHexing(String rawTxHex) {
  rawTxHex = rawTxHex.replaceFirst("0x", ""); // Remove the 0x prefix
  assert(rawTxHex.startsWith("01"), "Invalid Type 1 Transaction");
  rawTxHex = rawTxHex.substring(2); // Remove the type prefix

  final rlpDecoded = decodeRLP(rawTxHex.hexToBytes, 0).result;

  if (rlpDecoded is! List) {
    throw Exception("Error RLP decoding transaction: $rlpDecoded");
  }

  if (rlpDecoded.length < 8) {
    throw Exception("Invalid transaction, missing fields: $rlpDecoded");
  }

  final chainId = parseAsHexInt(rlpDecoded[0]);
  final nonce = parseAsHexBigInt(rlpDecoded[1]);
  final gasPrice = parseAsHexBigInt(rlpDecoded[2]);
  final gasLimit = parseAsHexBigInt(rlpDecoded[3]);
  final to = "0x" + rlpDecoded[4];
  final value = parseAsHexBigInt(rlpDecoded[5]);
  final data = (rlpDecoded[6] as String).hexToBytes;
  final accessList = [
    for (final item in rlpDecoded[7])
      (
        address: "0x" + item[0],
        storageKeys: (item[1] as List<dynamic>).whereType<String>().toList(),
      )
  ];

  return RawEVMTransactionType1.unsigned(
    nonce: nonce,
    gasLimit: gasLimit,
    to: to,
    value: value,
    data: data,
    chainId: chainId,
    gasPrice: gasPrice,
    accessList: accessList,
  );
}