sendTransaction method
- EthereumAddress? address,
- EthereumData? data, {
- EthereumAddress? 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 Ethereum 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<EthereumData?> sendTransaction(
EthereumAddress? address, EthereumData? data,
{EthereumAddress? to,
int gas = 9000,
int? gasPrice,
int? value,
int? nonce}) async {
if (address == null) {
throw ArgumentError.notNull('Ethereum::sendTransaction - address');
}
if (data == null) {
throw ArgumentError.notNull('Ethereum::sendTransaction - data');
}
const method = EthereumRpcMethods.sendTransaction;
var paramBlock = <String, String?>{
'from': address.asString,
'to': to?.asString,
'gas': 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)
};
paramBlock =
EthereumUtilities.removeNull(paramBlock) as Map<String, String?>;
final dynamic params = <dynamic>[paramBlock];
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;
}