0
votes

Im trying to compile my contracts but solidity cant find a method in a contract that I am importing and using in another contract. I get this error.

/home/a/Documents/so/contracts/incidents.sol:188:9: TypeError: Member "burn" not found or not visible after argument-dependent lookup in type(contract Token)
        Token.burn(_amount);

My import looks like this

import "./token.sol";

this is the function that uses the burn method.

function buyRep(uint _amount) {
    uint repAmount = _amount.mul(3);
    profiles[msg.sender].uRep.repToGive.add(repAmount);
    Token.burn(_amount);
}

the contract the above method is in doesnt inherit the Token contract but when I set it to inherit from the Token contract and just do burn(_amount). I get another error. PLease help me understand this.

This is the function inside the Token contract inside token.sol.

function burn(uint256 _value) public returns (bool success) {
    require(balances[msg.sender] >= _value);   // Check if the sender has enough
    balances[msg.sender] -= _value;            // Subtract from the sender
    _totalSupply -= _value;                      // Updates totalSupply
    //emit Burn(msg.sender, _value);
    return true;
}
1

1 Answers

0
votes

Try adding is to derive from your token.sol contract. Derived contracts access all non-private members (state variables and internal functions as well). For more info on inheritance between contracts check out this article.

import "./ContractB.sol";

contract ContractA is ContractB {

    function buyRep(uint _amount) public {
      burn(_amount);
    }
}

'

contract ContractB {

    function burn(uint256 _value) public returns (bool success) {
       require(balances[msg.sender] >= _value);   // Check if the sender has enough
       balances[msg.sender] -= _value;            // Subtract from the sender
       _totalSupply -= _value;                      // Updates totalSupply
       //emit Burn(msg.sender, _value);
       return true;
  }
}