Transaction parameters

Transaction parameters are:

  1. Gas price;
  2. Gas limit;
  3. Maturity.

You can configure these parameters by creating an instance of TxParameters:

pub struct TxParameters {
    pub gas_price: u64,
    pub gas_limit: u64,
    pub maturity: u64,
}

and passing it to a chain method called tx_params:

        let contract_methods = MyContract::new(contract_id.clone(), wallet.clone()).methods();

        // In order: gas_price, gas_limit, and maturity
        let my_tx_params = TxParameters::new(None, Some(1_000_000), None);

        let response = contract_methods
            .initialize_counter(42) // Our contract method.
            .tx_params(my_tx_params) // Chain the tx params setting method.
            .call() // Perform the contract call.
            .await?; // This is an async call, `.await` for it.

You can also use TxParameters::default() to use the default values:

pub const DEFAULT_GAS_LIMIT: u64 = 1_000_000;
pub const DEFAULT_GAS_PRICE: u64 = 0;
pub const DEFAULT_MATURITY: u64 = 0;

This way:

        let response = contract_methods
            .initialize_counter(42)
            .tx_params(TxParameters::default())
            .call()
            .await?;

As you might have noticed already, TxParameters can also be specified when deploying contracts or transfering assets by passing it to the respective methods.

Note: whenever you perform an action that results in a transaction (contract deployment, contract call, asset transfer), the SDK will automatically estimate the fee based on the set gas limit and the transaction's byte size. This estimation is used when building the transaction. A side-effect of this is that your wallet must at least own a single coin of the base asset of any amount.