I'm relatively new to Flutter and blockchain and I'm trying to create simple app. For start i create my own wallet and it is OK, I get credentials and address. I get balance with web3 getBalance method, and gas info with estimateGas and getGasPrice.
When I want to send some coin using sendTransaction method, I get the transaction hash, but when I check it on polygonscan it is stuck on pending status.
I'm sure addresses are OK, because I can coin from my metamask wallet and it is updated in my app.
Here is the code:
await _web3client.estimateGas().then((value) async {
maxGas = value.toString();
var result = null;
await _web3client.getGasPrice().then((value) async {
print(value);
try {
var transaction = Transaction(
to: EthereumAddress.fromHex(controller.text),
gasPrice:
EtherAmount.fromUnitAndValue(EtherUnit.wei, value.getInWei),
maxGas: int.parse(maxGas),
value: EtherAmount.fromUnitAndValue(EtherUnit.ether, 5),
);
result = await _web3client.sendTransaction(_credentials, transaction,
chainId: 80001);
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(result.toString()),
duration: const Duration(seconds: 5)));
await _web3client.dispose();
print(result.toString());
} catch (error, trace) {
print("Error: " + error.toString());
print("Trace " + trace.toString());
}
});
});