RawEVMTransactionType0.fromUnsignedHex constructor

RawEVMTransactionType0.fromUnsignedHex(
  1. String messageHex
)

Implementation

factory RawEVMTransactionType0.fromUnsignedHex(String messageHex) {
  final rawTxHex = messageHex.replaceFirst("0x", "");
  final rlpDecoded = decodeRLP(rawTxHex.hexToBytes, 0).result;

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

  final decodedList = rlpDecoded.whereType<String>().toList();

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

  final nonce = parseAsHexBigInt(decodedList[0]);
  final gasPrice = parseAsHexBigInt(decodedList[1]);
  final gasLimit = parseAsHexBigInt(decodedList[2]);
  final to = "0x" + decodedList[3];
  final value = parseAsHexBigInt(decodedList[4]);
  final data = decodedList[5].hexToBytes;

  final chainId =
      decodedList.length > 6 ? parseAsHexInt(decodedList[6]) : null;

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