4

Let us consider a following contract generated by the wizard

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract SomeClassNameHere is ERC20 {
    constructor() ERC20("MyToken", "MTK") {}
}

the class name is SomeClassNameHere. I wonder if that is relevant. Could I re-use same class name for many projects? I suppose after compiled to EVM there will be no trace of it anyway. Could someone confirm?

3
  • if you have 2 contracts with the same name in truffle or hardhat project then you will get an error. But on the blockchain, there is no map or register for contracts name so you can deploy 10^100 different contracts with the same name. However, the name is shown on etherscan and will confuse you and the users
    – Majd TL
    Commented Dec 3, 2021 at 8:22
  • @MajdTL I think you mean the contract name, not the contract class name. Could you clarify?
    – Marek
    Commented Dec 3, 2021 at 8:28
  • the contract name "should" be the class name. / docs.soliditylang.org/en/v0.8.10/…
    – Majd TL
    Commented Dec 3, 2021 at 8:31

2 Answers 2

3

The name does not affect functionality of the contract in any way. Compiling the same source with just the name changed will give you the same exact bytecode (except for the metadata hash embedded at the end).

Any change in the source will affect the metadata though. The consequence is that the contract will not pass verification on services that compare both bytecode and metadata (like Sourcify). Most other verification services (e.g. Etherscan) ignore metadata though and will accept source even with much bigger modifications. Anything that does not affect the bytecode itself (changed contract names, variable names, file names and paths, comments, unused code that gets optimized out) will pass.

Could I re-use same class name for many projects?

You can actually reuse it even in the same project. You can give multiple contracts the same name as long as you don't import them into the same file. And even then you can work around it by using the import ... as ... syntax and giving them different names locally.

1
  • I wonder if that is relevant. No but it can help you. contract name would help to know what to expect from a certain contract without looking at code or documentation, even if you aren’t the person who created it or if it was written a long time ago.

  • Could I re-use same class name for many projects? No problem.

1
  • thanks for sharing your inputs here. Sorry for reaching you out of the blue. I was wondering if you could assist me with this. I am kind of not finding any information anywhere else. ethereum.stackexchange.com/questions/118130/… Thanks a ton in advance. Commented Jan 6, 2022 at 22:02

Your Answer

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

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