toJson method

Map<String, dynamic> toJson()

Converts the transaction details into a json.

Implementation

Map<String, dynamic> toJson() {
  return {
    'type': type?.toString(),
    'to': to?.toString(),
    'from': from.toString(),
    'nonce': "0x${nonce.toRadixString(16)}",
    'gasLimit': "0x${gasLimit.toRadixString(16)}",
    'gasPrice': gasPrice == null ? null : "0x${gasPrice!.toRadixString(16)}",
    'maxPriorityFeePerGas': maxPriorityFeePerGas == null
        ? null
        : "0x${maxPriorityFeePerGas!.toRadixString(16)}",
    'maxFeePerGas':
        maxFeePerGas == null ? null : "0x${maxFeePerGas!.toRadixString(16)}",
    'data': data.isEmpty ? null : BytesUtils.toHexString(data, prefix: "0x"),
    'value': "0x${value.toRadixString(16)}",
    'chainId': "0x${chainId.toRadixString(16)}",
    'accessList': accessList?.map((e) => e.toJson()).toList(),
    "signature": signature == null
        ? null
        : {
            "s": signature!.s.toString(),
            "r": signature!.r.toString(),
            "v": signature!.v
          }
  };
}