0

In last there is code of burning tokens please help me i am getting this error

TypeError: Indexed expression has to be a type, mapping or array (is function (address) view returns (uint256)) --> Token.sol:51:17: | 51 | require(balanceOf[msg.sender] >= _value); | ^^^^^^^^^

pragma solidity ^0.8.2;

contract Token {
    mapping(address => uint) public balances;
    mapping(address => mapping(address =>uint)) public allowance;
    
    uint public totalSupply =10000000000 * 10 ** 18;
    string public name = "The Mouse";
    string public symbol = "MIK";
    uint public decimals = 18;

    event Transfer(address indexed from, address indexed to, uint_value);
    event Approval(address indexed owner, address indexed spender, uint_value);
    constructor(){
        balances[msg.sender] = totalSupply;
    }
    
    function balanceOf(address owner) public view returns(uint){
        return balances[owner];
        
    }
    
    function transfer(address to, uint_value) public returns(bool){
        require(balanceOf(msg.sender) >=_value, 'balaNce too low');
        balances[to] +=_value;
        balances[msg.sender] -=_value; 
        emit Transfer(msg.sender, to,_value);
        return true;
        
    }
    
    function transferFrom(address from, address to, uint value) public returns(bool){
        require(balanceOf(from) >= , 'balance tOo low');
        require(allowance[from][msg.sender] >= _value, 'allowance too low');
        balances[to] += _value;
        balances[from] -= _value;
        emit Transfer(from, to, _value);
        return true;
   
    }   

    
    function approve(address spender, uint value) public returns(bool){
        allowance[msg.sender][spender] = _value;
        emit Approval(msg.sender, spender , _value);
        return true;
    }
    
    
    function burn (uint256 _value) public returns (bool success){
        require(balanceOf[msg.sender] >= _value);
        
        balanceOf[msg.sender] -= _value;
        totalSupply -= __value;
        return true;
        
    }
    
    function burnFrom (address _from, uint256 _value) public returns(bool success) {
    require(balanceOf[_from] >= _value);
    require(_value <= allowance[_from][msg.sender]);
    
    balanceOf[_from] -= _value;
    totalSupply -= _value;

        return true;
        
    }
    
}
1

In your contract balanceOf() is a function, so it must be invoked with the correct syntax, i.e. brackets -> ( and ).

In your contract balances[] is a mapping, so each member must be accessed with the correct syntax, i.e. square brackets -> [ and ].


The error is stating that you are trying to invoke the balanceOf() function using square brackets [].


Also, this line has two underscores -> totalSupply -= __value;

You need to remove one of the underscores...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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