Truffle Upgrades: Error: Artifacts are from different compiler runs

Hello @abcoathup,

I understand what you’re saying (Deploying to Quorum with OpenZeppelin CLI), I decided to go ahead to try deploying and upgrading a contract on a private ethereum blockchain using the plugin you suggested. I decided to follow this tutorial: OpenZeppelin Truffle Upgrades: Step by Step Tutorial but as I deploy the upgraded contract via the 4_prepare_upgrade_boxv2.js migration (I skipped the ownership transfer as I just wanted to get the upgrade to work), I get an error saying: “Error: Artifacts are from different compiler runs”. Artifcats being from a different compiler runs shouldn’t cause an issue? Or, how else am I supposed to deploy a new version of a contract.

Here is a more detailed description of what I did so you can try to reproduce the error:

  1. mkdir mycontract && cd mycontract
    npm init -y
    npm i --save-dev truffle
    npx truffle init
    npm i --save-dev @openzeppelin/truffle-upgrades

  2. Create a Box.sol inside the contracts folder, code:

    pragma solidity ^0.5.0;
    
    import "@openzeppelin/upgrades/contracts/Initializable.sol";
    
    contract Box is Initializable{
    uint256 private value;
    
    function initialize(uint256 _value) initializer public {
    	value = _value;
    }
    
    function retrieve() public view returns (uint256) {
     return value;
    }}
    
  3. Edit truffle-config.js to use solc version: “^0.5.0”

  4. Create a new migration file:

     const Box = artifacts.require('Box');
      
     const { deployProxy } = require('@openzeppelin/truffle-upgrades');
      
     module.exports = async function (deployer) {
       await deployProxy(Box, [42], { deployer, initializer: 'initialize' });
     };
    
  5. Deploy via truffle to local network -> Everything deploys successfully! :slight_smile:

  6. Create new version of contract, BoxV2.sol:

    pragma solidity ^0.5.0;
    
     import "@openzeppelin/upgrades/contracts/Initializable.sol";
    
     contract BoxV2 is Initializable{
     uint256 private value;
    
     function initialize(uint256 _value) initializer public {
     	value = _value;
     }
    
     // Reads the last stored value
     function retrieve() public view returns (uint256) {
         return value;
     }
     
     function increment() public {
         value = value + 1;
     }
    }
    
  7. Create new migration file:

    const Box = artifacts.require('Box');
    const BoxV2 = artifacts.require('BoxV2');
    
    const { prepareUpgrade } = require('@openzeppelin/truffle-upgrades');
    
    module.exports = async function (deployer) {
    const box = await Box.deployed();
    await prepareUpgrade(box.address, BoxV2, { deployer });
    };
    
  8. Deploy via truffle again, now it fails :frowning: saying:

Error: Artifacts are from different compiler runs
Run a full recompilation using truffle compile --all


Running truffle compile -all as it suggests didn’t help. Please let me know what I’m doing wrong here. Thank you very much for your help so far :slight_smile:

1 Like

Hi @Alex-dev,

I am sorry that you are having this issue. Thank you so much for creating reproduceable steps.

I ran through what you described and after running into Error: Artifacts are from different compiler runs I was able to resolve by running npx truffle compile --all.

You can also try deleting build/contracts directory. See the documentation for an explanation on this: https://docs.openzeppelin.com/upgrades-plugins/1.x/faq#why-do-i-have-to-recompile-all-contracts-for-truffle

Would you mind trying that and let me know if you still run into issues.

As an aside, if you want to jump straight to the upgrade you can use upgradeProxy

For completeness, below is the steps I took:

...
3_prepare.js
============

Error: Artifacts are from different compiler runs
    Run a full recompilation using `truffle compile --all`
    https://zpl.in/upgrades/truffle-recompile-all
...
$ npx truffle compile --all

Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
> Compiling ./contracts/Box.sol
> Compiling ./contracts/BoxV2.sol
> Compiling ./contracts/Migrations.sol
> Compiling @openzeppelin/upgrades/contracts/Initializable.sol
✔ Fetching solc version list from solc-bin. Attempt #1
> Artifacts written to /home/abcoathup/projects/forum/alex-dev/build/contracts
> Compiled successfully using:
   - solc: 0.5.17+commit.d19bba13.Emscripten.clang
$ npx truffle migrate

Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
> Everything is up to date, there is nothing to compile.



Starting migrations...
======================
> Network name:    'development'
> Network id:      1600375667969
> Block gas limit: 6721975 (0x6691b7)


3_prepare.js
============

   Deploying 'BoxV2'
   -----------------
   > transaction hash:    0x4c16a1a5e6607fbeeed00c46380c017c47014d8b6d93bfa39fc80bf465e75221
   > Blocks: 0            Seconds: 0
   > contract address:    0x9561C133DD8580860B6b7E504bC5Aa500f0f06a7
...

Hello @abcoathup,

I deleted the build/contracts directory as you suggested and ran truffle migrate again but this caused all the migration files to run again (1. migration, 2. first deploy, 3. second deploy). My understanding is that only the latest migration should be re-run. Otherwise, doesn’t this mean that the old contract is deployed again to a new address which the new contract is “linked” to?

EDIT:
Using npx truffle compile -all doesn’t seem to re-compile the contracts as expected. I am getting the message: Everything is up to date…

However, adding the compile all flag to the migrate command seems to do the job. Like so: npx truffle migrate --compile-all.

So, I’m not sure if I did something incorrectly. But what I draw from this is that you should always use the “–compile-all” command when migrating.

Cheers & thanks for your detailed response.

2 Likes