encodeTransaction function
Encodes the transaction object to be in a format supported by the Smart Contracts and Circuits. Used, for example, to sign the transaction
@param {Object} transaction - Transaction object returned by generateL2Transaction @param {String} providerUrl - Network url (i.e, http://localhost:8545). Optional
@returns {Object} encodedTransaction
Implementation
Map<String, dynamic> encodeTransaction(Map<String, dynamic> transaction,
{String? providerUrl}) {
final Map<String, dynamic> encodedTransaction = Map.from(transaction);
encodedTransaction["chainId"] = getCurrentEnvironment()!.chainId;
encodedTransaction["fromAccountIndex"] =
getAccountIndex(transaction["fromAccountIndex"]);
if (transaction["toAccountIndex"] != null) {
encodedTransaction["toAccountIndex"] =
getAccountIndex(transaction["toAccountIndex"]);
} else if (transaction["type"] == 'Exit') {
encodedTransaction["toAccountIndex"] = 1;
}
if (transaction["toHezEthereumAddress"] != null) {
encodedTransaction["toEthereumAddress"] =
getEthereumAddress(transaction["toHezEthereumAddress"]);
}
return encodedTransaction;
}