1

I am trying to create an ERC20 token for the first time and keep running into this issue. "Expected identifier but got 'public'solidity(2314)"

No matter what I do it seems to be a problem but I don't get what I'm doing wrong here. I want to assign owner to msg.sender so it has to be public and without public there it causes an error with my import statement for some reason.

Anyone have any ideas as where I should go from here?

//SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.0; 

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract UNITED is ERC20 {
    constructor(uint256 initialSupply) ERC20("United Token", "UNITED"){
        address payable public owner;
        _mint(msg.sender, initialSupply);
    }

}

1 Answer 1

1

You cannot declare a local variable as public. Local variables are variables declared inside functions or the constructor, etc.

You have this line inside the constructor:

address payable public owner;

It should be outside the constructor:

pragma solidity ^0.8.0; 

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract UNITED is ERC20 {

    address payable public owner;

    constructor(uint256 initialSupply) ERC20("United Token", "UNITED"){
        _mint(msg.sender, initialSupply);
    }

}

Then you can assign msg.sender to owner in the constructor like:

pragma solidity ^0.8.0; 

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract UNITED is ERC20 {

    address payable public owner;

    constructor(uint256 initialSupply) ERC20("United Token", "UNITED"){
        owner = msg.sender;
        _mint(msg.sender, initialSupply);
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.