0
//SPDX-License-Identifier:MIT
pragma solidity ^0.6.0;

contract myTest2
{
    address payable owner;
    event Minted(address ownerAddress,string message);
    event transfer(address sender, string message2);

constructor () public
{
    owner = msg.sender;
}

function mint() payable external
{
    require(msg.value == 2 ether,"Not enough amount transfered to mint");
    emit Minted(msg.sender,"Minted");
}

The below Function gives me error: DeclarationError: Identifier already declared. function transfer(address payable recipient)payable external{ ^ (Relevant source part starts here and spans across multiple lines). The previous declaration is here: event transfer(address sender, string message2); ^----------------------------------------------^

function transfer(address payable recipient)payable external{
    if(recipient == owner)
    {
        owner.transfer(msg.value);
    }
    else
    {
        recipient.transfer(msg.value);
    }
    emit transfer(msg.sender,"Transaction Successfull");
}
}
1
  • There's a transfer event, with lowercase t.
    – Ismael
    Jun 20 at 6:14

1 Answer 1

1

You have an event and a function with the same name transfer, usually event starts with a capital letter so change the event declaration to this

event Transfer(address sender, string message2);

and then the call to

emit Transfer(msg.sender,"Transaction Successfull");

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.