ethereum/go-ethereum · error · Error

The contract code couldn't be stored, please check your gas

Error message

The contract code couldn't be stored, please check your gas amount.

What it means

During contract deployment confirmation, web3 fetched the receipt and then called getCode on the receipt's contractAddress. If the deployed address holds no code (!code), it concludes the constructor did not store bytecode and reports that the contract code could not be stored, suggesting the gas amount is wrong. Classic signature: the deployment tx was mined but OUT_OF_GAS, leaving an empty contract.

Source

Thrown at internal/jsre/deps/web3.js:2933

                            if(code.length > 3) {

                                // console.log('Contract code deployed!');

                                contract.address = receipt.contractAddress;

                                // attach events and methods again after we have
                                addFunctionsToContract(contract);
                                addEventsToContract(contract);

                                // call callback for the second time
                                if(callback)
                                    callback(null, contract);

                            } else {
                                if(callback)
                                    callback(new Error('The contract code couldn\'t be stored, please check your gas amount.'));
                                else
                                    throw new Error('The contract code couldn\'t be stored, please check your gas amount.');
                            }
                        });
                    }
                });
            }
        }
    });
};

/**
 * Should be called to create new ContractFactory instance
 *
 * @method ContractFactory
 * @param {Array} abi
 */
var ContractFactory = function (eth, abi) {
    this.eth = eth;
    this.abi = abi;

View on GitHub (pinned to 6bb0588ad8)

Solutions

  1. Raise the gas limit for the deploy transaction (estimate first if possible) and redeploy.
  2. Inspect the receipt's gasUsed vs the gas sent: gasUsed == gas limit strongly indicates out-of-gas.
  3. Check the constructor logic for reverts/throws and that all library placeholders (__$...$__) were linked.
  4. Redeploy to a fresh address; the failed attempt leaves a useless empty contract.

Example fix

// before
contract.new({from: acct, data: code, gas: 100000}, cb);

// after
contract.new({from: acct, data: code, gas: 4700000}, cb);
Defensive patterns

Strategy: validation

Try / catch

contract.new(opts, function (err, c) {
  if (err && /gas amount/.test(err.message)) {
    // deployment mined but empty: bump gas and redeploy to a new address
    opts.gas = Math.floor(opts.gas * 1.5);
    contract.new(opts, arguments.callee.bind(null));
  }
});

Prevention

When it happens

Trigger: contract.new({data: ..., gas: N}) where N is less than the constructor's actual execution cost; the transaction is mined, receipt.contractAddress exists, but getCode returns empty. Also triggered by a constructor that reverts (failing assert/require or throw in old Solidity).

Common situations: Underestimating deployment gas (especially large bytecode or expensive constructors), Solidity 0.4.x 'throw' in the constructor, or a linked-library placeholder left unresolved causing the constructor to fail.

Related errors


AI-assisted analysis of ethereum/go-ethereum@6bb0588ad8 (2026-08-15). Data as JSON: /api/errors/a251a1ea76b8e355. Report an issue: GitHub.