sendTransaction method

Future<int> sendTransaction (BigInt address, BigInt data, { BigInt to, int gas: 9000, int gasPrice, int value, int nonce })

Send transaction Creates new message call transaction or a contract creation, if the data field contains code. address: The address the transaction is sent from. to: (optional when creating new contract) The address the transaction is directed to. gas: (optional, default: 90000) Integer of the gas provided for the transaction execution. It will return unused gas. gasPrice: (optional, default: To-Be-Determined) Integer of the gasPrice used for each paid gas value: (optional) Integer of the value send with this transaction data: The compiled code of a contract OR the hash of the invoked method signature and encoded parameters. For details see Moac Contract ABI nonce: optional) 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<int> sendTransaction(BigInt address, BigInt data,
    {BigInt to, int gas = 9000, int gasPrice, int value, int nonce}) async {
  if (address == null) {
    throw ArgumentError.notNull("Moac::sendTransaction - address");
  }
  if (data == null) {
    throw ArgumentError.notNull("Moac::sendTransaction - data");
  }
  final String method = MoacRpcMethods.sendTransaction;
  Map<String, String> paramBlock = {
    "from": MoacUtilities.bigIntegerToHex(address),
    "to": to == null ? null : MoacUtilities.bigIntegerToHex(to),
    "gas": MoacUtilities.intToHex(gas),
    "gasPrice": gasPrice == null ? null : MoacUtilities.intToHex(gasPrice),
    "value": value == null ? null : MoacUtilities.intToHex(value),
    "data": MoacUtilities.bigIntegerToHex(data),
    "nonce": nonce == null ? null : MoacUtilities.intToHex(nonce)
  };
  paramBlock = MoacUtilities.removeNull(paramBlock);
  final dynamic params = [paramBlock];
  final res = await rpcClient.request(method, params);
  if (res != null && res.containsKey(moacResultKey)) {
    return MoacUtilities.hexToInt(res[moacResultKey]);
  }
  _processError(method, res);
  return null;
}