RawEVMTransactionType2.fromHex constructor
RawEVMTransactionType2.fromHex( - String rawTxHex
)
Implementation
factory RawEVMTransactionType2.fromHex(String rawTxHex) {
rawTxHex = rawTxHex.replaceFirst("0x", ""); // Remove the 0x prefix
assert(rawTxHex.startsWith("02"), "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 < 12) {
throw Exception("Invalid transaction, missing fields: $rlpDecoded");
}
final chainId = parseAsHexInt(rlpDecoded[0]);
final nonce = parseAsHexBigInt(rlpDecoded[1]);
final maxPriorityFeePerGas = parseAsHexBigInt(rlpDecoded[2]);
final maxFeePerGas = parseAsHexBigInt(rlpDecoded[3]);
final gasLimit = parseAsHexBigInt(rlpDecoded[4]);
final to = "0x" + rlpDecoded[5];
final value = parseAsHexBigInt(rlpDecoded[6]);
final data = (rlpDecoded[7] as String).hexToBytes;
final accessList = [
for (final item in rlpDecoded[8])
(
address: "0x" + item[0],
storageKeys: (item[1] as List<dynamic>).whereType<String>().toList(),
)
];
final signatureYParity = parseAsHexInt(rlpDecoded[9]);
final signatureR = (rlpDecoded[10] as String).hexToBytes;
final signatureS = (rlpDecoded[11] as String).hexToBytes;
return RawEVMTransactionType2(
nonce: nonce,
gasLimit: gasLimit,
to: to,
value: value,
data: data,
chainId: chainId,
maxFeePerGas: maxFeePerGas,
maxPriorityFeePerGas: maxPriorityFeePerGas,
accessList: accessList,
signatureR: signatureR,
signatureS: signatureS,
signatureYParity: signatureYParity,
);
}