I kept on getting this error. 9/10 of my deployment will fail. But out of the sudden it will be success without any reason.

I have checked the transaction receipt and indeed it had reaches the gas limit. The weird thing is, no matter how high I set, the limit will always be hit (until it reaches the block gas limit)

Saving successful migration to network...
  ... 0x4767ac8dbe6496fad283fd0185557f1fa56bd8772f9e6e727a385a31938d7179
  ... 0xeab261e0b015da89e96607cc20de26678a1d75c88fc1d5307ac526aad539d15d
Saving artifacts...
(node:7376) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: The contract code couldn't be stored, please check your gas amount.
(node:7376) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

truffle Configuration

development: {
  host: "localhost",
  port: 8545,
  from: "0xc8caa71c16299b40b8579742a27ee53162886040",
  gas: "900000000",
  gasPrice: "3000000000",
  network_id: "*" // Match any network id

The ciritcal part of the migration script:

deployer.deploy(L).then(async () => {
  deployer.deploy(X, L.address);

The X is failing. It's constructor is depending on the address of L. If your earlier guess is correct, then most likely this is the part that gives error.

  • Are you deploying to a private network, public testnet or mainnet? What is your truffle network configuration? Are your contracts complex? – Ismael Dec 22 '18 at 3:52
  • Thanks. I am deploying to a private network. Let me update with truffle network configuration.... wait. – s k Dec 22 '18 at 4:17
  • It is possible that a constructor is failing, another possibility is that your migration script has a bug. What is your migration script that deploy your contracts? Are you using truffle v4 or the new v5? – Ismael Dec 22 '18 at 4:42
  • I am using Truffle V4, that is why I see the error. In V5 it doesn't show any error, but deployment still fail. Let me add the migration script. Please wait. – s k Dec 22 '18 at 4:55
  • From the error message the exception occurs after starting to save artifacts. Are you using async/await in your migrations scripts? they are not supported directly in truffle v4 github.com/trufflesuite/truffle/issues/501. – Ismael Dec 22 '18 at 6:35

It very likely is a valid contract is too large error. One thing you can try is to add the optimizer to your solidity compiler config, which will be located in your truffle.js config file. This will run a process on the assembly code during compilation, making it more efficient.

You can find a more detailed explanation here

compilers: {
    solc: {
        version: "^0.5.0",
        settings: {
            optimizer: {
                enabled: true,
                runs: 200

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.