3

I am creating an app that has various imports that require two different versions of solidity. AragonOS(0.4.x) and openzeppelin(0.5.x)

Of course, there are breaking changes in 0.5.x so my question is this. Is it possible to tell truffle to compile some contracts with a different compiler than others within the same project? If not how could I get around this problem

  • You could use an earlier version of openzeppelin (2.0.0 or even 1.12.0), which relies on solc 0.4.x. With it, use truffle 4.1.15, or if you insist on truffle 5.x, then force solc 0.4.25 in the truffle-config.js file. – goodvibration Aug 6 at 20:05
  • 1
    @goodvibration I'm using create-aragon-app which is equivalent of create react app, it bundles everything with it. For sure I can use an earlier version of Zeppelin but I would rather use the latest where possible, – Python Pete Aug 6 at 20:18
  • Can you separate into two projects, one using OpenZeppelin Contracts and one using AragonOS? AragonOS has an open issue for upgrading to 0.5. github.com/aragon/aragonOS/issues/304 – abcoathup Aug 7 at 4:02
3

EDIT: I recommend using Buidler! The key feature their software provides is modularity, where compilation and testing of contracts can be done separately. Migration from Truffle is also seamless, as specified in their guide.

What you can do is to specify 2 separate configuration files for compilation of your v4 and v5 contracts, then use the --config flag.

For testing, use the --no-compile flag to skip contract compilation.

Example:

  • v4 contracts located in ./contracts/v4 folder
  • v5 contracts located in ./contracts/v5 folder
  • Test files located in ./test folder

1) Specify a configV4.js file with the following code:

module.exports = {
  defaultNetwork: "develop",

  networks: {
    develop: {
      gas: 6000000
    }
  },

  solc: {
    version: "0.4.18",
    optimizer: {
      enabled: true,
      runs: 200
    }
  },

  paths: {
    sources: "./contracts/v4",
  },
};

2) Specify a configV5.js file with the following code:

module.exports = {
  defaultNetwork: "develop",

  networks: {
    develop: {
      gas: 6000000
    }
  },

  solc: {
    version: "0.5.9",
    optimizer: {
      enabled: true,
      runs: 200
    }
  },

  paths: {
    sources: "./contracts/v5",
  },
};

3) Compile your v4 contracts: npx buidler compile --config configV4.js

4) Compile your v5 contracts: npx buidler compile --config configV5.js

5) For testing, you can specify yet another file configTest.js, or combine the settings in either config file mentioned above.

usePlugin("@nomiclabs/buidler-truffle5");

module.exports = {
  defaultNetwork: "develop",

  networks: {
    develop: {
      gas: 6000000
    }
  },

  paths: {
    tests: "./tests", 
    cache: "./cache",
    artifacts: "./artifacts"
  },

  mocha: {
    enableTimeouts: false
  }
};

6) Test your contracts: npx buidler test --no-compile --config configTest.js

  • I think you may mean npx buidler test --no-compile --config configTest.js? – Franco Sep 3 at 16:07
  • Ahhh yes, good catch! =p – Desmond Ho Sep 4 at 6:50
1

Brownie allows you to use multiple versions of solidity within the same project. All that's required is setting the compiler version to null within your project's config file. From the documentation:

If the version is set to null, Brownie looks at the version pragma of each contract and uses the latest matching compiler version that has been installed. If no matching version is found, the most recent release is installed. Setting the version via pragma allows you to use multiple versions in a single project.

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.