Icon SunFilledIcon MoonStars

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

await expect(
	contract.functions
	.return_context_amount()
	.callParams({
	  forward: [10, BaseAssetId],
	  gasLimit: 1,
	})
	.call()
).rejects.toThrow(/OutOfGas/);

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 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,
	})
	.call();
 
const {
	transactionResult: { transaction },
	value,
} = result;
 
expect(new BN(value).toNumber()).toBe(10);
expect(new BN(transaction.gasLimit).toNumber()).toBe(transactionGasLimit);

Was this page helpful?