Put in order · Blockchain and Web3 course · Module 7: Contract Interaction

Sorting: Gas estimation before a transaction

Arrange the steps for optimizing gas before sending a transaction:

Items to put in order

  • Add a buffer: const gasLimit = gasEstimate * 120n / 100n
  • Estimate gas: const gasEstimate = await contract.myFunc.estimateGas(args)
  • Send with a custom gas limit: await contract.myFunc(args, { gasLimit })
  • Wait for confirmation

You can check the correct answer by solving this task in the CodeWorlds game.