Icon HelpCircleForumIcon Link

⌘K

Icon HelpCircleForumIcon Link
Call Parameters

Icon LinkCall Parameters

When interacting with contracts, you can configure specific parameters for contract calls using the callParams method. The available call parameters are:

  1. forward
  2. gasLimit
Icon InfoCircle

Note: Setting transaction parameters is also available when calling contracts. More information on this can be found at Transaction Parameters .

Icon LinkForward Parameter

The forward parameter allows the sending of a specific amount of coins to a contract when a function is called. This is useful when a contract function requires coins for its execution, such as paying fees or transferring funds. The forward parameter helps you control the resources allocated to the contract call and offers protection against potentially costly operations.

const amountToForward = 10;
 
const { value } = await contract.functions
  .return_context_amount()
  .callParams({
    forward: [amountToForward, BaseAssetId],
  })
  .call();
 
expect(new BN(value).toNumber()).toBe(amountToForward);

Icon LinkGas Limit Parameter

The gasLimit refers to the maximum amount of gas that can be consumed specifically by the contract call itself, separate from the rest of the transaction.

const { minGasPrice } = provider.getGasConfig();
 
await expect(
  contract.functions
    .return_context_amount()
    .callParams({
      forward: [10, BaseAssetId],
      gasLimit: 1,
    })
    .txParams({ gasPrice: minGasPrice })
    .call()
).rejects.toThrow(/Gas limit '1' is lower than the required: /);

Icon LinkCall Parameters gasLimit vs Transaction Parameters gasLimit

The Call gasLimit parameter sets the maximum gas allowed for the actual contract call, whereas the Transaction gasLimit (see Transaction Parameters ) sets the maximum gas allowed for the entire transaction and constrains the gasLimit for the Call. If the Call gasLimit is set to a value greater than the available Transaction gas, then the entire available Transaction gas will be allocated for the contract call execution.

If you don't set the gasLimit for the Call, the Transaction gasLimit will be applied.

Icon LinkSetting Both Parameters

You can set both Call Parameters and Transaction Parameters within the same contract function call.

const { minGasPrice } = provider.getGasConfig();
const amountToForward = 10;
const contractCallGasLimit = 100;
const transactionGasLimit = 3_000_000;
 
const result = await contract.functions
  .return_context_amount()
  .callParams({
    forward: [amountToForward, BaseAssetId],
    gasLimit: contractCallGasLimit,
  })
  .txParams({
    gasLimit: transactionGasLimit,
    gasPrice: minGasPrice,
  })
  .call();
 
const {
  transactionResult: { transaction },
  value,
} = result;
 
expect(new BN(value).toNumber()).toBe(10);
expect(new BN(transaction.scriptGasLimit).toNumber()).toBe(transactionGasLimit);