web3dart
web3dart copied to clipboard
transaction settings for generated contract code
If I understood everything correctly, then in the current implementation we cannot pass the gas price, nonce and other parameters, except for the function arguments when calling the smart contract generated methods. Equally important is the network identifier parameter, because of which we cannot use the generated code for test networks.
A possible solution is to add an optional parameter of the container of additional settings to the list of arguments of those methods in which the transaction is created. This container will contain and pass to transaction constructor all other transaction settings as: gasPrice, nonce, maxGas, chainId, value.
Equally important is the network identifier parameter, because of which we cannot use the generated code for test networks
You can set the chainId in the generated constructor. But I agree that there should be a way to change the other parameters for calls:
- If the call doesn't write data, there should be a
BlockNum atBlockparameter to view historical data - If the call requires a transaction, there should be a way to set all transaction parameters (except sender, receiver and data)
We also need a way to make this backwards compatible. Perhaps we could add an optional Transaction parameter and make the generated contract call copyWith for the fields its setting itself.
You can set the
chainIdin the generated constructor. But I agree that there should be a way to change the other parameters for calls:
Thanks, i misssed it;
What about some new class "TransactionSettings" like this:
class TransactionSettings {
int? maxGas;
BigInt? gasPrice;
_i1.EtherAmount? value;
int? nonce;
TransactionSettings({
this.maxGas,
this.gasPrice,
this.value,
this.nonce,
});
}
whose instance we can pass to call that requires transaction:
Future<String> transfer(
_i1.EthereumAddress _to,
BigInt _value,
{
required _i1.Credentials credentials,
// NEW:
TransactionSettings? txSettings,
}
) async {
final function = self.function('transfer');
final params = [_to, _value];
final transaction = _i1.Transaction.callContract(
contract: self,
function: function,
parameters: params,
// NEW:
gasPrice: txSettings?.gasPrice,
maxGas: txSettings?.maxGas,
value: txSettings?.value,
nonce: txSettings?.nonce,
);
return write(credentials, transaction);
}
This way does not require backward compatibility, but need to have new class.
But we also can`t estimate gas for transaction in current implementation.
I've added some more parameters in af4c3fb4a0c258f4146f051e4c27d1674046003b, it works similar to what you're describing.
Estimating gas is a good point, maybe we should generate another method that returns a Transaction without running it? :thinking: