transact method
Implementation
Future<void> transact({
required String privateKey,
String? value,
String? from,
String? to,
}) async {
try {
web3.EtherAmount? val = null;
if (value != null) {
val = web3.EtherAmount.fromBase10String(web3.EtherUnit.wei, value);
}
web3.EthereumAddress? fromAddress = null;
if (from != null) {
fromAddress = web3.EthereumAddress.fromHex(from);
}
web3.EthereumAddress? toAddress = null;
if (to != null) {
toAddress = web3.EthereumAddress.fromHex(to);
}
final credentials = web3.EthPrivateKey.fromHex(privateKey);
var gasPrice = await this.client.getGasPrice();
var chainId = await this.client.getNetworkId();
final transaction = web3.Transaction(
from: fromAddress, to: toAddress, value: val, gasPrice: gasPrice);
final response = await this.client.sendTransaction(
credentials,
transaction,
chainId: chainId,
);
print(response);
} catch (e) {
print(e);
}
}