Coin Flip - Can't compile smart contract @openzeppelin [Solved]

Iā€™m getting these errors when trying to compile smart contract. Am using Linux. Have already run npm install @openzeppelin/contracts and modified truffle config as shown in tutorial

  compilers: {
    solc: {
      version: "0.7.5",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    }
  },
$ truffle compile

Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/flipcontract.sol
> Compiling ./node_modules/@openzeppelin/contracts/access/Ownable.sol

> Compilation warnings encountered:

    project:/contracts/flipcontract.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

project:/contracts/flipcontract.sol:2:1: ParserError: Source "project:/node_modules/@openzeppelin/contracts/math/SafeMath.sol" not found
import "../node_modules/@openzeppelin/contracts/math/SafeMath.sol";
^-----------------------------------------------------------------^
,project:/node_modules/@openzeppelin/contracts/access/Ownable.sol:3:1: ParserError: Source file requires different compiler version (current compiler is 0.7.5+commit.eb77ed08.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.8.0;
^---------------------^

Error: Truffle is currently using solc 0.7.5, but one or more of your contracts specify "pragma solidity ^0.8.0".
Please update your truffle config or pragma statement(s).
(See https://trufflesuite.com/docs/truffle/reference/configuration#compiler-configuration for information on
configuring Truffle to use a specific solc compiler version.)

Compilation failed. See above.
Truffle v5.4.7 (core: 5.4.7)
Node v13.12.0


$ truffle version
Truffle v5.4.7 (core: 5.4.7)
Solidity - 0.7.5 (solc-js)
Node v13.12.0
Web3.js v1.5.2

I solved this by specifying the version of open zeppelin. In the tutorial it shows to simply run npm install @openzeppelin/contracts, I removed and ran npm install @openzeppelin/[email protected]

2 Likes