Why am I getting "transaction out of gas" errors?

A common error message that Kaleido users have encountered when trying to execute smart contract transactions is “out-of-gas.” This document describes some of the known causes and potential fixes.

Here are some definitions of terms related to gas. The referenced eth APIs are part of the Web3.js library.

  • gas: unit of measurement for the computational work of running transactions or smart contracts in the Ethereum network
  • gasLimit: maximum amount of gas that can be spent on all transactions within a single block. This is not configurable by Kaleido users.
    • Listed as gasLimit in output of eth.getBlock("<block_hash>")
    • The miner of a new block can set the gas limit within +/- 0.1 % of the parent block’s gas limit
  • gas provided: maximum amount of gas you’re willing to spend on a particular transaction
    • Listed as gas in output of eth.getTransaction("<transaction_hash>")
  • gasPrice: the amount of Ether you’re willing to pay for every unit of gas, measured in Gwei (1 ETH = 1M Gwei)
    • Listed as gasPrice in output of eth.getTransaction("<transaction_hash>")

Common Symptoms, Causes and Solutions

  • “Gas provided” for transaction is not high enough to cover the gas needed to execute the transaction.
    • Likely error message: intrinsic gas too low.
    • Fix: Supply a higher gas amount, or use a client like the Kaleido REST API Gateway that automatically estimates gas for your transactions (importantly also adding a 20% contingency on top before submission)
  • The from account does not have enough Ether to execute transaction.
    • Likely error message: insufficient funds for gas * price + value
    • Note: This will only occur if the gasPrice for the transaction is set to some value other than the default 0.
    • Fix: Use a debugger like Remix to debug your infinite loop
  • Infinite loop or other unbounded processing error in smart contract code
    • Likely error message TX ran out of gas before completion
    • Fix: Use a debugger like Remix to debug your infinite loop
  • Contract is not compiled for the correct EVM version
    • Likely error message gas required exceeds allowance or always failing transaction
    • Fix: Compile with --evm-version byzantium
    • Note: If you need more recent opcodes, please contact us to confirm the hard fork that is supported in Kaleido and meets your needs.
  • Contract has reverted
    • Likely error message gas required exceeds allowance or always failing transaction
    • Fix: Run eth_call with exactly the same parameters, then process the output per the Solidity control structures doc to get the error message of the revert
    • Note: Some web3 interfaces, including Truffle, and the Kaleido REST API Gateway, perform an eth_call automatically for you when this occurs during gas estimation and return the error string, rather than the generic message