signTransaction method

Future<String> signTransaction({
  1. required String from,
  2. String? to,
  3. Uint8List? data,
  4. int? gas,
  5. BigInt? gasPrice,
  6. BigInt? value,
  7. int? nonce,
})

Signs a transaction that can be submitted to the network at a later time using with eth_sendRawTransaction. from - The address the transaction is send from. to - The address the transaction is directed to. data - The compiled code of a contract OR the hash of the invoked method signature and encoded parameters. For details see Ethereum Contract ABI. gas - (default: 90000) Integer of the gas provided for the transaction execution. It will return unused gas. gasPrice - Integer of the gasPrice used for each paid gas (in Wei). value - Integer of the value sent with this transaction (in Wei). nonce - Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.

Returns the signed transaction data.

Implementation

Future<String> signTransaction({
  required String from,
  String? to,
  Uint8List? data,
  int? gas,
  BigInt? gasPrice,
  BigInt? value,
  int? nonce,
}) async {
  final result = await connector.sendCustomRequest(
    method: 'eth_signTransaction',
    params: [
      {
        'from': from,
        if (data != null) 'data': hex.encode(List<int>.from(data)),
        if (to != null) 'to': to,
        if (gas != null) 'gas': '0x${gas.toRadixString(16)}',
        if (gasPrice != null) 'gasPrice': '0x${gasPrice.toRadixString(16)}',
        if (value != null) 'value': '0x${value.toRadixString(16)}',
        if (nonce != null) 'nonce': '0x${nonce.toRadixString(16)}',
      }
    ],
  );

  return result;
}