sendTransaction method

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

Creates new message call transaction or a contract creation, if the data field contains code 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 transaction hash, or the zero hash if the transaction is not yet available.

Implementation

Future<String> sendTransaction({
  required String from,
  String? to,
  Uint8List? data,
  int? gas,
  BigInt? gasPrice,
  BigInt? value,
  int? nonce,
}) async {
  final result = await connector.sendCustomRequest(
    method: 'eth_sendTransaction',
    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;
}