luther wardle
luther wardle

Reputation: 469

truffle compile contracts specifying incorrect solidity version

getting really bugged down by this, trying to code an ERC21 collectible and when I compile my projects with truffle compile... I am getting an error Truffle is currently using solc 0.5.16, but one or more of your contracts specify "pragma solidity ^0.8.0"

I find this odd because I have edited the version within my contracts and within my package.lock.json, tried deleting my package-lock, changed versions in contracts then tried running npm install again but I get the same error no matter what version I use

I have had this error previously in other projects but just fixed it by correcting the version... but that's not working this time :(

I have tried pragma solidity >=0.4.21 <0.6.0; and 0.6.0 and 0.5.16 ^0.5.16 and 0.8.0 and ^0.8.0 I have tried changing the lock file accordingly with no luck

hoping someone can explain what I'm doing wrong?

contract example

pragma solidity >=0.4.21 <0.6.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract color is ERC721 {
    constructor() ERC721("color", "COLOR") {
    }
}

truffle.config

require('babel-register');
require('babel-polyfill');

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*" // Match any network id
    },
  },
  contracts_directory: './src/contracts/',
  contracts_build_directory: './src/abis/',
  compilers: {
    solc: {
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  }
}

package-lock.json

"truffle": {
      "version": "5.0.5",
      "resolved": "https://registry.npmjs.org/truffle/-/truffle-5.0.5.tgz",
      "requires": {
        "app-module-path": "^2.2.0",
        "mocha": "^4.1.0",
        "original-require": "1.0.1",
        "solc": "^0.8.0"
      }
    },

Upvotes: 0

Views: 1878

Answers (1)

Sam Marvasti
Sam Marvasti

Reputation: 118

I had the same problem :( check your package.json for older versions of solidity libraries. I specified version 0.8 in the truffle-config that got me further with OpenZepplin latest contracts but still some old contracts using 0.5 and it fails. I resolved it with editing the package.json to point to latest openzepplin then

npm install --upgrade

then

truffle compile --all

Can we list multiple solidity compilers in truffle?

    module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // for more about customizing your Truffle configuration!
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*" // Match any network id
    },
    develop: {
      port: 8545
    },
    nftWallet: {
      provider: () => new PrivateKeyProvider(privateKey, "http://localhost:8545"),
      network_id: "*",
      type: "quorum",
      gasPrice: 0
    }
  },
        //Configure your compilers
   compilers: {
     solc: {
        version: "0.8",    // Fetch exact version from solc-bin (default: truffle's version)

           }
   }

};

Upvotes: 1

Related Questions