RawEVMTransactionType0.fromHex constructor

RawEVMTransactionType0.fromHex(
  1. String messageHex
)

Implementation

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

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

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

  final nonce = rlpDecoded[0].buffer.toUBigInt;
  final gasPrice = rlpDecoded[1].buffer.toUBigInt;
  final gasLimit = rlpDecoded[2].buffer.toUBigInt;
  final to = "0x" + rlpDecoded[3].hex;
  final value = rlpDecoded[4].buffer.toUBigInt;
  final data = rlpDecoded[5].buffer;

  final v = rlpDecoded[6].buffer.toUInt;
  final r = rlpDecoded[7].buffer.toUBigInt;
  final s = rlpDecoded[8].buffer.toUBigInt;

  return RawEVMTransactionType0(
    nonce: nonce,
    gasPrice: gasPrice,
    gasLimit: gasLimit,
    to: to,
    value: value,
    data: data,
    v: v,
    r: r,
    s: s,
  );
}