When I set import to "@openzeppelin/contracts/etc/etc" VS Code immediately shows not found. File import call back not supported but running truffle compile shows what I think looks better (considering the output). When I change the import to "node_modules/@openzeppelin/contracts/etc/etc" VS code likes it but truffle compile output now A) shows WAY more contracts, B) hits me with errors like "this function; this var; has already been delcared". It shows the error in live in my files and points to the relevant imported source contract as the first to declare. I can't get truffle solc-js compiler to understand that these are separate contracts and it is a reference... It's like both the imported and my contracts are in the same folder or something. (but are not).
I have changed the names of literally everything (I think) except for my CrowSale sol file name. I just can't figure out which combination of attempts is the right one or maybe it is a config setting and not a naming or syntax issue.
Questions
Why are the contents of imported contracts like ERC20.sol creating a declaration error based on the contents of my contracts. Where are/is my error(s) in the A) File Name B) import call C) contract declaration D) or in deployment artifacts require(a file) naming scheme?
my environment
Truffle v5.5.0 (core: 5.5.0)
Ganache v7.0.1
Solidity - ^0.5.0 (solc-js)
Node v14.9.0
Web3.js v1.5.3
CrowdSale sol "mine"
// SPDX-License-Identifier: ISC
pragma solidity >=0.5.0 <6.0;
import "node_modules/@openzeppelin/contracts/crowdsale/Crowdsale.sol";
import "./myToken.sol";
contract CrowdSale{
address payable admin;
myToken public tokenContract;
uint256 public tokenPrice;
uint256 public tokensSold;
event Sell(address _buyer, uint256 _amount);
constructor (myToken _tokenContract, uint256 _tokenPrice) public {
admin = msg.sender;
tokenContract = _tokenContract;
tokenPrice = _tokenPrice;
}
myToken sol
// SPDX-License-Identifier: ISC
pragma solidity >=0.5.0 <6.0;
import "node_modules/@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
import "node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract myToken is ERC20, ERC20Detailed {
string public name = "myToken";
string public symbol = "myToken";
uint256 public totalSupply; //removed = _amount;state variables
constructor(
string memory _name,
string memory _symbols,
unit8 _decimals,
unit256 _amount
) public ERC20Detailed(_name, _symbols, _decimals) {
_mint(msg.sender, _amount);
}
2 deploy contracts js
// SPDX-License-Identifier: MIT
var myToken = artifacts.require("./myToken.sol");
var CrowdSale = artifacts.require("./CrowdSale.sol");
module.exports = function(deployer) {
deployer.deploy(myToken, 100001).then(function() {
var tokenPrice = 17000000000000000000;
return deployer.deploy(CrowdSale, myToken.address, tokenPrice);
});
};
##Edited / added
Compiling ./contracts/Migrations.sol
> Compiling ./contracts/PreSale.sol
> Compiling ./contracts/tFief.sol
> Compiling @openzeppelin/contracts/GSN/Context.sol
> Compiling @openzeppelin/contracts/crowdsale/Crowdsale.sol
> Compiling @openzeppelin/contracts/math/SafeMath.sol
> Compiling @openzeppelin/contracts/token/ERC20/ERC20.sol
> Compiling @openzeppelin/contracts/token/ERC20/ERC20Detailed.sol
> Compiling @openzeppelin/contracts/token/ERC20/IERC20.sol
> Compiling @openzeppelin/contracts/token/ERC20/SafeERC20.sol
> Compiling @openzeppelin/contracts/utils/Address.sol
> Compiling @openzeppelin/contracts/utils/ReentrancyGuard.sol
project:/contracts/tFief.sol:13:1: DeclarationError: Identifier already declared.
contract ERC20Detailed {
^ (Relevant source part starts here and spans across multiple lines).
project:/contracts/tFief.sol:10:1: The previous declaration is here:
import '@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol';
^-------------------------------------------------------------^
,project:/contracts/tFief.sol:23:1: DeclarationError: Identifier already declared.
contract ERC20 is ERC20Detailed {
^ (Relevant source part starts here and spans across multiple lines).
project:/contracts/tFief.sol:11:1: The previous declaration is here:
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';