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
- Raise the gas limit for the deploy transaction (estimate first if possible) and redeploy.
- Inspect the receipt's gasUsed vs the gas sent: gasUsed == gas limit strongly indicates out-of-gas.
- Check the constructor logic for reverts/throws and that all library placeholders (__$...$__) were linked.
- 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
- Estimate deployment gas generously (bytecode size x 200 + constructor cost).
- Check receipt.gasUsed === tx.gas as an out-of-gas smell test before interpreting the error.
- Ensure all library link placeholders are resolved before deploy.
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
- Contract transaction couldn't be found after 50 blocks
- This unit doesn't exists, please use the one of the followin
- Cannot send value to non-payable constructor
- Filter ID Error: filter().get() can't be chained synchronous
- Cannot send value to non-payable function
AI-assisted analysis of ethereum/go-ethereum@6bb0588ad8 (2026-08-15).
Data as JSON: /api/errors/a251a1ea76b8e355.
Report an issue: GitHub.