Getting the following error when trying to migrate the constructor of OpenZeppelin ERC20 Contract
@openzeppelin/contracts/token/ERC20/ERC20.sol:55:5: Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
constructor (string memory name_, string memory symbol_) public {
^ (Relevant source part starts here and spans across multiple lines).
,/C/Users/Asusupernova/Documents/ETH/LastCreator/contracts/MyToken.sol:7:5: Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
constructor(uint256 initialSupply) public ERC20("Liberation", "LIB") {
^ (Relevant source part starts here and spans across multiple lines).
Visibility ( public / external ) is not needed for constructors anymore: To prevent a contract from being created, it can be marked abstract . This makes the visibility concept for constructors obsolete.
I assume that you are actually compiling with Solidity 0.7?
As you are inheriting from OpenZeppelin Contracts, then you may be better to have a pragma solidity that is at least as narrow as what you are inheriting. See: Simple ERC20 token example.
I updated the syntax and am encountering another error. This is not even part of my code. Online solutions just seem to be project specific. Btw, is asking questions the only way to trouble shoot or there is another way?
2_deploy_contracts.js
=====================
C:\Users\Asusupernova\AppData\Roaming\npm\node_modules\truffle\build\commands.bundled.js:828606
.replace(/^\.\//, "")
^
TypeError: Cannot read property 'replace' of undefined
at ResolverIntercept.require (C:\Users\Asusupernova\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\ResolverIntercept.js:10:1)
As for resolving issues like this, it is mostly doing it multiple times so that you can then identify where the issue is likely occurring, e.g. contract, migrations script, test, configuration etc, and then you can just work on that one piece.
When you get stuck, you can start again, and if you still get stuck then you can ask the community. It is worth trying to create a simple example which shows the issue, and often this helps you identify what is the cause.
Yea, am going over those links even as we speak, I’ve been using tutorials which were written in Solidity 0.6, and I only recently learnt that I should try as much as possible to use the most updated version
So far it seems like 50% of the job as a programmer is tinkering with the program till it works
Migrations.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.21 <0.8.0;
contract Migrations {
address public owner;
uint public last_completed_migration;
modifier restricted() {
if (msg.sender == owner) _;
}
constructor()public {
owner = msg.sender;
}
function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}
}
MyToken.sol
pragma solidity >=0.4.21 <0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract My is ERC20 {
constructor(uint256 initialSupply) ERC20("Liberation", "LIB") {
_mint(msg.sender, initialSupply);
}
}
1_initial_migration.js
var Migrations = artifacts.require("./Migrations.sol");
module.exports = function(deployer) {
deployer.deploy(Migrations);
};
2_deploy_contract.js
var MyToken = artifacts.require(MyToken);
module.exports = async function (deployer) {
await deployer.deploy(MyToken, 'Liberation', 'LIB', 100000);
}
I tend to use Solidity 0.6 or Solidity 0.7. Solidity 0.8 just got released today.
There were a couple of issues. Your token contract was named My but in the migrations script you were trying to use MyToken. Your constructor only takes one parameter, but in the migrations script you were trying to pass three parameters.
Why & How ?
Contructor run only once, so solidity says : "don't make it public, you don't need to make it public, its contructor, not a function to be declared as public"