web3dart icon indicating copy to clipboard operation
web3dart copied to clipboard

transaction settings for generated contract code

Open andromeda911 opened this issue 4 years ago • 3 comments

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.

andromeda911 avatar Jun 24 '21 08:06 andromeda911

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 atBlock parameter 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.

simolus3 avatar Jun 24 '21 20:06 simolus3

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:

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.

andromeda911 avatar Jun 24 '21 20:06 andromeda911

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:

simolus3 avatar Jun 24 '21 20:06 simolus3