Skip to content

Call 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

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

Forward 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.

ts
const amountToForward = 10;

const { waitForResult } = await contract.functions
  .return_context_amount()
  .callParams({
    forward: [amountToForward, provider.getBaseAssetId()],
  })
  .call();

const { value } = await waitForResult();

expect(new BN(value).toNumber()).toBe(amountToForward);
See code in context

Gas 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.

ts

await expect(async () => {
  const call = await contract.functions
    .return_context_amount()
    .callParams({
      forward: [10, provider.getBaseAssetId()],
      gasLimit: 1,
    })
    .call();

  await call.waitForResult();
}).rejects.toThrow('The transaction reverted with reason: "OutOfGas"');
See code in context

Call 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.

Setting Both Parameters

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

ts
const amountToForward = 10;
const contractCallGasLimit = 4000;
const transactionGasLimit = 100_000;

const { waitForResult } = await contract.functions
  .return_context_amount()
  .callParams({
    forward: [amountToForward, provider.getBaseAssetId()],
    gasLimit: contractCallGasLimit,
  })
  .txParams({
    gasLimit: transactionGasLimit,
  })
  .call();

const result = await waitForResult();
const { value } = result;
const expectedValue = 10;

expect(new BN(value).toNumber()).toBe(expectedValue);
See code in context