alex schobel
alex schobel

Reputation: 95

browser/Test.sol:5:21: TypeError: Definition of base has to precede definition of derived contract contract test is owned ^---^

I am having a problem that I really don't know how to solve, I was doing a tutorial on making smart contracts on solidity to launch on Ethereum for a future university project. The error i was getting is the one above in the title. I will copy the code so you can see what i was have and highlight the line of code of the error. I couldn't figure out what was the problem because i was to ambiguous the type error plus I'm new to solidity.

pragma solidity ^0.4.24;

contract NLtoken is owned
{
    
    uint public totalSupply;
    string public name;
    string public symbol;
    uint8 public decimals = 18;
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowence;
    event Transfer (address indexed _from, address indexed _to, uint tokens);
    event Approval (address indexed _tokenOwner, address indexed _spender, uint tokens);
    
    constructor  (string tokenName, string tokenSymbol, uint initialSupply) public {
        totalSupply = initialSupply*10**uint256(decimals);
        balanceOf[msg.sender] = initialSupply;
        name = tokenName;
        symbol = tokenSymbol;
    }
    function _transfer (address _from, address _to, uint256 _value) internal returns(bool success){
       require(_to != 0x0);
        require(balanceOf[_from] >= _value);
        require(balanceOf[_to] + _value >= balanceOf[_to]);
        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;
        emit Transfer(_from, _to, _value);
        return true;
    }
    
    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 <= allowence[_from][msg.sender]);
        allowence[_from][msg.sender] -= _value;
        _transfer(_from, _to, _value);
        return true;
        
    }
    function approve(address _spender, uint256 _value) public returns (bool success)
    {
        allowence[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 succes)
    {
        require (balanceOf[msg.sender] >= _value);
        balanceOf[msg.sender] -= _value;
        totalSupply -= _value;
        emit burn(msg.sender, _value);
        return true;
        
    }

        
}
contract owned  {
    
    address public owner;
    constructor ()
    {
        owner = msg.sender;
    }
     modifier  onlyOwner
    {
        require(msg.sender == owner);
        _;
    }
    function transferOwnership(address  newOwner) onlyOwner {
        owner = newOwner;
    }
    
}

Upvotes: 0

Views: 644

Answers (2)

Charles
Charles

Reputation: 455

For anyone else having this issue, none of the answers I found were particularly clear about what the issue was, but Mad Jackal's post above was good enough for me to figure it out.

In my case, a contract which I was trying to inherit from referenced another contract which imported a third separate contract, and in the third contract I was trying to also inherit this same thing, creating a circular dependency lookup.

Upvotes: 0

Mad Jackal
Mad Jackal

Reputation: 1249

Declare owned contract before NLtoken contract. And keep in mind that the event name is case sensitive:

emit Transfer(0, owner, _mintedAmount);
emit Transfer (owner, _target,_mintedAmount);

Upvotes: 1

Related Questions