open zeppelin contracts are missing in node_modules - solidity

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);
}
}

Related

Solidity, hardhat failing to compile multiple Solidity versions

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

Remote Solidity Compiler vs LocalNodeModule

I was writing Solidity contract like this:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "#openzeppelin/contracts/access/Ownable.sol";
contract Contract {}
However, I received this error
"Source "#openzeppelin/contracts/access/Ownable.sol" not found: File import callback not supported"
For context, I am using latest Solidity extension v0.0.139 and 0.8.15 for global compiler version (Remote). If I change compiler to LocalNodeModule, I will have issue with pragma solidity ^0.8.13 statement. How can I fix this?
did you run:
npm install #openzeppelin/contracts ??
I think this should fix the issue
First, verify if the file Ownable.sol is installed by checking if it exists under node_modules/#openzeppelin/contracts/access/
if it does not exist then launch the command: npm install #openzeppelin/contracts
if it does exist, then it could be a problem with your editor try to close and re-open your file ( happened to me once )

Can't import openzeppelin library into smart contract in brownie framework

I can't import openzeppelin's ERC721 contract.
I have installed it using brownie pm install and also added it to brownie-config.yaml
I appreciate any help
Test.sol
brownie-config.sol
It seems this is just the solidity extension on vs code. It can't read the remapping so it throws an error when trying to import. However, when I compile the contract using bronwie compile it works.

How to compile older zeppelin-solidity contract implementations

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

Solidity error: Expected identifier, got 'LParen'

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).