personalSendTransaction method

Future<EthereumData?> personalSendTransaction(
  1. EthereumAddress? address,
  2. String? passphrase, {
  3. EthereumAddress? to,
  4. EthereumAddress? data,
  5. int? gas,
  6. int? gasPrice,
  7. int? value,
  8. int? nonce,
  9. int? condition,
  10. bool conditionIsTimestamp = false,
})

Validate the given passphrase and submit transaction. The transaction is the same argument as for eth.sendTransaction and contains the from address.

Note that an extra parameter is condition :- Conditional submission of the transaction. Can be either an integer block number { block: 1 } or UTC timestamp (in seconds) { time: 1491290692 } or null.

If the passphrase can be used to decrypt the private key belonging to tx.from the transaction is verified, signed and send onto the network. The account is not unlocked globally in the node and cannot be used in other RPC calls.

Implementation

Future<EthereumData?> personalSendTransaction(
    EthereumAddress? address, String? passphrase,
    {EthereumAddress? to,
    EthereumAddress? data,
    int? gas,
    int? gasPrice,
    int? value,
    int? nonce,
    int? condition,
    bool conditionIsTimestamp = false}) async {
  if (address == null) {
    throw ArgumentError.notNull(
        'Ethereum::personalSendTransaction - address');
  }
  if (passphrase == null) {
    throw ArgumentError.notNull(
        'Ethereum::personalSendTransaction - passphrase');
  }
  Map<String, String>? conditionObject = <String, String>{};
  if (condition == null) {
    conditionObject = null;
  } else {
    if (conditionIsTimestamp) {
      conditionObject = <String, String>{
        'timestamp': EthereumUtilities.intToHex(condition)
      };
    } else {
      conditionObject = <String, String>{
        'block': EthereumUtilities.intToHex(condition)
      };
    }
  }
  final paramBlock = <String, dynamic>{
    'from': address.asString,
    'to': to?.asString,
    'gas': gas == null ? null : EthereumUtilities.intToHex(gas),
    'gasPrice':
        gasPrice == null ? null : EthereumUtilities.intToHex(gasPrice),
    'value': value == null ? null : EthereumUtilities.intToHex(value),
    'data': data?.asString,
    'nonce': nonce == null ? null : EthereumUtilities.intToHex(nonce),
    'condition': conditionObject
  };
  const method = EthereumRpcMethods.psendTransaction;
  final dynamic params = <dynamic>[paramBlock, passphrase];
  final dynamic res = await _client.rpcClient.request(method, params);
  if (res != null && res.containsKey(EthereumConstants.ethResultKey)) {
    return EthereumData.fromString(res[EthereumConstants.ethResultKey]);
  }
  _client.processError(method, res);
  return null;
}