Warning: Duplicate contract names found for A with contract and interface with same name

Hi,
I have the following two contracts, Contract A is given by:

pragma solidity ^0.5.8;
contract A {
   address owner;
   constructor() public{  
      owner = msg.sender;
   }
   function transferTo(address to, uint amount) public {  
      (bool success,) = to.call.value(amount)("");
      require(success);
   }
   function() external payable  {}
}

Contract B is given by:

//B.sol
pragma solidity ^0.5.8;
interface A {  
   function transferTo(address to, uint amount) external;
}

contract B {
   address owner;
   constructor () public {  owner = msg.sender;}
   function getOwner() public view returns (address) {  return owner;}
   function() external payable  { 
      A(msg.sender).transferTo(owner, msg.sender.balance);
   }
}

When I compile the code on Truffle console, I am getting the following warning: Duplicate contract names found for A. Somebody please guide me how to remove this warning.

Although I am using hardhat, I believe it’s because your Interface and your Contract are both named A.

Generally interface names should start with I, in your case it should be named IA to follow naming conventions to signify it being an interface.

Attached is an image to show the compilation. You might want to inherit your contracts and declare some of them as abstract if you are trying to get functionality from one contract to another.

3 Likes