1

Newbie here: I'm getting so many errors trying to compile a simple Token contract. I don't know what I'm doing wrong or how to fix it. Can anyone help please?

enter image description here enter image description here

Compile contract failed: ["fs://7c1b8c34-918c-4ac2-951b-2acb02bce6e3/root/MadToken.sol:26:5: DeclarationError: Identifier already declared.\n function balanceOf(address _owner) public view returns (uint256) \n ^ (Relevant source part starts here and spans across multiple lines).\nfs://7c1b8c34-918c-4ac2-951b-2acb02bce6e3/root/MadToken.sol:17:5: The previous declaration is here:\n mapping(address => uint256) \n ^ (Relevant source part starts here and spans across multiple lines).\n","fs://7c1b8c34-918c-4ac2-951b-2acb02bce6e3/root/MadToken.sol:57:5: DeclarationError: Identifier already declared.\n function allowance(address _owner, address _spender) public view returns (uint256 remaining) {\n ^ (Relevant source part starts here and spans across multiple lines).\nfs://7c1b8c34-918c-4ac2-951b-2acb02bce6e3/root/MadToken.sol:19:5: The previous declaration is here:\n mapping(address => mapping(address => uint256)) \n ^ (Relevant source part starts here and spans across multiple lines).\n","fs://7c1b8c34-918c-4ac2-951b-2acb02bce6e3/root/MadToken.sol:58:16: DeclarationError: Undeclared identifier.\n return allowed[_owner][_spender];\n ^-----^\n"]

1 Answer 1

1

It's a good idea to post your actual code, and not a screenshot.

In this code, the compiler is telling you that you have duplicate identifier names. Line 26 uses name balanceOf for the function name, but you have already named your mapping variable balanceOf

Similar problem with Line 57, you use allowance as the function name, but have already declared a mapping variable called allowance

You need to use unique names for all identifiers (variables, functions, classes etc)

Your Answer

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

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