RawEVMTransactionType1.fromHex constructor
RawEVMTransactionType1.fromHex( - String rawTxHex
)
Implementation
factory RawEVMTransactionType1.fromHex(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 < 11) {
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(),
)
];
final signatureYParity = parseAsHexInt(rlpDecoded[8]);
final signatureR = (rlpDecoded[9] as String).hexToBytes;
final signatureS = (rlpDecoded[10] as String).hexToBytes;
return RawEVMTransactionType1(
nonce: nonce,
gasLimit: gasLimit,
to: to,
value: value,
data: data,
chainId: chainId,
gasPrice: gasPrice,
accessList: accessList,
signatureYParity: signatureYParity,
signatureR: signatureR,
signatureS: signatureS,
);
}