0
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;
    }

I get this error when trying to compile a contract in remix:

DeclarationError: Identifier already declared. --> Token.sol:23:5: | 23 | 
function transfer(address to, uint value) public returns(bool) { | ^ (Relevant source part starts here and spans across multiple lines). Note: The previous declaration is here: --> Token.sol:12:5: | 12 | event transfer(address indexed from, address indexed to, uint value); | 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1
  • Hi! The error you posted mentions a line that isn't present in your code - it says you also have an event called transfer. Is this the case?
    – Linum Labs
    May 4 at 14:09
0

Your event and function transfer have the same name. Change your function name.

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.