Icon LinkTransaction parameters

The parameters for a transaction are:

  1. Gas price
  2. Gas limit
  3. Maturity

You can configure these parameters by creating an instance of TxParameters and passing it to a chain method called tx_params:

let contract_methods = MyContract::new(contract_id.clone(), wallet.clone()).methods();
 
let my_tx_parameters = TxParameters::default()
    .with_gas_price(1)
    .with_gas_limit(1_000_000)
    .with_maturity(0);
 
let response = contract_methods
    .initialize_counter(42) // Our contract method.
    .tx_params(my_tx_parameters) // 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_PRICE: u64 = 0;
pub const DEFAULT_GAS_LIMIT: u64 = 10_000_000;
pub const DEFAULT_MATURITY: u32 = 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.