RawEVMTransactionType0.fromUnsignedHex constructor

RawEVMTransactionType0.fromUnsignedHex(
  1. String messageHex
)

Implementation

factory RawEVMTransactionType0.fromUnsignedHex(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 < 6) {
    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 chainId = rlpDecoded.length > 6 ? rlpDecoded[6].buffer.toUInt : null;

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