0

it keeps bringing this error ParserError: Function, variable, struct or modifier declaration expected on this line of code public address owner; here is the full code

    pragma solidity ^0.4.24;

contract BasicToken is owned {
    uint public totalSupply;
    string public name;
    string public symbol;
    uint public decimals = 18;
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    event Transfer(address indexed _from, address indexed _to, uint tokens);
    event Approval(address indexed _tokenOwner, address indexed _spender, uint tokens);
    event Burn(address indexed _from, uint256 _value);
    

    constructor (string tokenName, string tokenSymbol, uint initialSupply) public {
        totalSupply = initialSupply*10**uint256(decimals);
        balanceOf[msg.sender]= totalSupply;
        name = tokenName;
        symbol = tokenSymbol;
    }

    function _transfer(address _from,address _to,uint256 _value ) internal {
        require(_to != 0x0);
        require(balanceOf[_from] >= _value);
        require(balanceOf[_to] + _value >= balanceOf[_to]);
        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;
        emit Transfer(_from, _to, _value);
    }

    function transfer(address _to, uint256 _value) public returns (bool success){
        _transfer(msg.sender, _to, _value);
        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){
        require(_value <= allowance[_from][msg.sender]);
        allowance [_from][msg.sender] -= _value;
        _transfer(_from, _to, _value);
        return true;
    }

    function approve(address _spender, uint256 _value) public returns(bool success){
        allowance[msg.sender][_spender] = _value;
        emit Approval (msg.sender, _spender, _value);
        return true;
    }

    function mintToken (address _target, uint256 _mintedAmount) onlyOwner {
        balanceOf[_target] += _mintedAmount;
        totalSupply += _mintedAmount;
        emit Transfer(0, owner, _mintedAmount);
        emit Transfer(owner, _target, _mintedAmount);
    }

    function burn(uint256 _value) onlyOwner returns(bool success) {
        require(balanceOf[msg.sender] >= _value);
        balanceOf[msg.sender] -= _value;
        totalSupply -= _value;
        emit Burn(msg.sender, _value);
        return true;
    }
}


contract owned {
    public address owner;

    constructor {
        owner = msg.sender;
    }

    modifier onlyOwner{
        require(msg.sender == owner);
        _;
    }

    function transferOwnership (address newOwner) onlyOwner{
        owner = newOwner;
    }
}

1 Answer 1

1

there are some errors:

in own contract

1- Instead of public address owner

   address public  owner;

2- instead of constructor

  constructor()

3- add visibility to transferOwnership. I added public

 function transferOwnership(address newOwner) public onlyOwner{

4- Since you are inhering from owner contract place it on top. Otherwise you get "definition of base has to precede definition of derived contract" error.

in BasicToken contract

1- add visibility like public to the last few functions

2- in constructor signature remove public (since I compiled at version 0.8.7 but in your version it was necessary I guess) and add memory for string args

constructor (string memory tokenName, string memory tokenSymbol, uint initialSupply) {

3-

  function _transfer(address _from,address _to,uint256 _value ) internal {
    // not 0x0 because _to is address type
    require(_to != 0x0000000000000000000000000000000000000000);
    // or require(_to != address(0);

4- in mintToken

function mintToken (address _target, uint256 _mintedAmount) public onlyOwner {
        balanceOf[_target] += _mintedAmount;
        totalSupply += _mintedAmount;
        // not 0, address(0)
        emit Transfer(address(0), owner, _mintedAmount);
        emit Transfer(owner, _target, _mintedAmount);
    }

I compiled it at version pragma solidity ^0.8.7;

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it was really helpful, the code is working perfectly now

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.