I installed zeppelin-solidity package using npm, to use the erc-721 contract.
But the problem is that when I use truffle compile, it gives the following error:
/Users/me/dev/myfolder/erc721/node_modules/zeppelin-solidity/contracts/token/ERC721/ERC721Token.sol:1:1: ParserError: Source file requires different compiler version (current compiler is 0.5.16+commit.9c3226ce.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.24;
^----------------------^
Error: Truffle is currently using solc 0.5.16, but one or more of your contracts specify "pragma solidity ^0.4.24".
Please update your truffle config or pragma statement(s).
(See https://truffleframework.com/docs/truffle/reference/configuration#compiler-configuration for information on
configuring Truffle to use a specific solc compiler version.)
Compilation failed. See above.
Some answers I saw are suggesting to bump up the pragma solidity to 0.5, but how can i change the version in an included file?
Also if this contract is old should i be using it, or are there better implementations of erc721 available?
UPDATE:
I have tried changing the solc compiler as below, but still the error persists:
compilers: {
solc: {
version: "^0.4.24",
//parser: "solcjs",
optimizer: {
enabled: true,
runs: 200
}
}
}
Write a file called truffle.js such as:
module.exports = {
// Configure your compilers
compilers: {
solc: {
version: ">=0.4.24", // Fetch exact version from solc-bin (default: truffle's version)
}
},
};
and place it under the project root directory. That's it.
Read more about Truffle configurations: https://www.trufflesuite.com/docs/truffle/reference/configuration
Related
I'm having this issue, even adding the versions in the hardhat.config file.
module.exports = {
solidity: {
compilers: [{version: "0.6.6"}, {version: "0.4.19"}, {version: "0.6.12"}, {version: "0.8.8"}, {version: "0.7.0"}]
},
Here is still the error, What can I do?? The contract works perfectly in remix.
Error HH606: The project cannot be compiled, see reasons below.
These files import other files that use a different and incompatible version of Solidity:
* contracts/MarketOrder.sol (^0.8.8) imports #openzeppelin/contracts/token/ERC20/ERC20.sol (^0.7.0)
To learn more, run the command again with --verbose
Read about compiler configuration at https://hardhat.org/config
Your MarketOrder.sol contract has been configured for Solidity 0.8, whereas the imported OpenZeppelin contract is Solidity 0.7
Update your #openzeppelin/contracts package to the latest version or at least one that supports ^0.8.0
I know is a typical error but I don't know how to solve it. I have tried to add the compile version in the hardhat config file but it doesn't work.
Error HH606: The project cannot be compiled, see reasons below.
These files import other files that use a different and incompatible version of Solidity:
contracts/MarketOrder.sol (^0.8.8) imports #openzeppelin/contracts/token/ERC20/ERC20.sol (^0.7.0)
To learn more, run the command again with --verbose
Read about compiler configuration at https://hardhat.org/config
Without adding the 0.7.0:
Error HH606: The project cannot be compiled, see reasons below.
The Solidity version pragma statement in these files doesn't match any of the configured compilers in your config. Change the pragma or configure additional compiler versions in your hardhat config.
* #openzeppelin/contracts/token/ERC20/ERC20.sol (^0.7.0)
* #openzeppelin/contracts/math/SafeMath.sol (^0.7.0)
* #openzeppelin/contracts/token/ERC20/IERC20.sol (^0.7.0)
These files import other files that use a different and incompatible version of Solidity:
* contracts/MarketOrder.sol (^0.8.8) imports #openzeppelin/contracts/token/ERC20/ERC20.sol (^0.7.0)
These files and its dependencies cannot be compiled with your config. This can happen because they have incompatible Solidity pragmas, or don't match any of your configured Solidity compilers.
* #uniswap/v3-periphery/contracts/libraries/TransferHelper.sol
To learn more, run the command again with --verbose
Read about compiler configuration at https://hardhat.org/config
Inside the hardhat.config file you can add multiple compiler versions, find the snippet similar to and add the compiler version which is required.
solidity: {
compilers: [
{
version: "0.8.8",
},
{
version: "0.7.0",
},
],
}
hardhat does not support https imports. After installing openzeppelin and chainlink with npm and using #openzeppelin/#chainlink, we get pragma/compiler version issues, even with different compiler versions in hardhat.config.js, and even with overwrites. How do you develop and compile with hardhat and these imports?
In your hardhat.config.js you can add multiple compilers.
module.exports = {
solidity: {
compilers: [
{
version: "0.6.6"
},
{
version: "0.4.24"
}
]
}
}
I faced this problem, i wanted to interface with Venus protocol....so i basically put all the interfaces and the contract inside one file with the contract to avoid running multiple instances of the solidity compiler.
I used npm install to install open zeppelin. the libray shows in node_modules but a lot of the contracts are missing. I've tried deleting it and reinstalling but I just keep getting errors about missing contracts.
Error: Could not find zeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol from any sources; imported from /home/a/Documents/coin/contracts/token.sol
at Resolver.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/packages/resolver/dist/lib/resolver.js:53:1)
at Generator.next (<anonymous>)
at fulfilled (/usr/local/lib/node_modules/truffle/build/webpack:/packages/resolver/dist/lib/resolver.js:5:42)
at <anonymous>
Truffle v5.1.28 (core: 5.1.28)
Node v8.10.0
Despite ERC20Detailed still being extant within OpenZeppelin's online tutorial it no longer exists when you download the package and take a peek inside. I therefore ran into exactly the same problem you did.
This is due to a breaking change introduced in OpenZeppelin Contracts 3.0, namely:
If you're using the ERC20 or ERC721 tokens however, you'll have to
remove all references to optional extensions (ERC20Detailed,
ERC721Enumerable, etc.) - these have been included in the base
contracts.
To get your code to work using version 3.0 you will have to use the standard ERC20 module. For a very basic example of importing and using that:
pragma solidity ^0.6.2;
import "#openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyCoin is ERC20 {
uint public initialSupply = 10000;
constructor() public ERC20("MyCoin", "MC") {
_mint(msg.sender, initialSupply);
}
}
I'm getting the error:
Expected identifier, got 'LParen'
Problem is, this code is from the Solidity docs! I have tried many thing for this error but to no avail. The link where I got the code is: https://solidity.readthedocs.io/en/latest/solidity-by-example.html
I have an image attached with the error:
Can someone explain to me what I'm doing wrong? I have the right version, as per below:
kalyan#kalyan:/usr/bin$ truffle version
Truffle v4.1.13 (core: 4.1.13)
Solidity v0.4.24 (solc-js)
This is running on Ubuntu 18.04. Is there something else I should be doing?
EDIT
The code before constructor is:
/// Modifiers are a convenient way to validate inputs to
/// functions. `onlyBefore` is applied to `bid` below:
/// The new function body is the modifier's body where
/// `_` is replaced by the old function body.
modifier onlyBefore(uint _time) { require(now < _time); _; }
modifier onlyAfter(uint _time) { require(now > _time); _; }
I have faced this problem with the constructor in solidity too this can be solved really easily
if you are running your code in VSCODE than you may have installed a extension
Solidity Extended
then you have then
UNININSTALL it and reload your vscode editor
if you may have uinstalled and not reloaded your vs code than you will
face same problem
> also set the pragma solidity version to pragma solidity >=0.4.21 < 0.7.0;
this worked for me
See the answer to a similar error here: https://ethereum.stackexchange.com/a/56727/27511
I'm reposting for convenience...
I had a similar problem. In my case it was the system version of solc I had installed. Here's what I had. I had solc installed through Homebrew, and also truffle installed. when I run truffle version:
Truffle v4.1.14 (core: 4.1.14)
Solidity v0.4.24 (solc-js)
So I had the latest version of truffle and seemingly, solc as well. However, when I run solc --version
solc, the solidity compiler commandline interface
Version: 0.4.19+commit.e67f0147.Darwin.appleclang
My system solidty version was different. I found that I had installed solidity through Homebrew (on Mac), so that was different from the version truffle was using. So the fix in my case, was to upgrade solidity using homebrew, it upgraded from 0.4.19 to 0.4.24 and my problem went away.
To upgrade solidity using Homebrew:
brew update
brew upgrade
brew tap ethereum/ethereum
brew install solidity
brew linkapps solidity
The first two lines are probably all you need if you already have solidity installed, but added the rest for completeness.
This was on Mac, if you're on Linux, it might be a similar problem, make sure you upgrade the system installation of solidity, not what's installed with truffle.
I fixed it by upgrading to the 0.5.0 compiler. I think there is something weird in 0.4 (like a change in language syntax).