Skip to content
Home » Answers » How To Find Out if an Ethereum Address Is a Contract?

How To Find Out if an Ethereum Address Is a Contract?

How to find out if an Ethereum Address is a Contract

Knowing whether an Ethereum address is a smart contract address or an EOA address is very crucial. We will be going through two methods to see how to determine the same.

Using Etherscan to look for Ethereum address

In Ethereum, the easiest way to determine whether an address is a contract is by going to Etherscan and pasting the address.

  1. Go to Etherscan: Navigate to the Etherscan website at https://etherscan.io/
  2. Search for the Address: In the search bar, enter the Ethereum contract address you want to check. And then click on search.
  3. View Address Information: Once you’ve searched for the address, you’ll be taken to the address’s details page on Etherscan. This page will show you information related to the address you have entered which is publicly available for everyone to view.
  4. Check the ‘Contract’ Section: If the address is a contract, on the address details page, there should be a section labeled “Contract” or “Contract Information.” If the address is a contract, this section will display details about the contract, such as its bytecode, creation transaction, entire code of the contract if it has been verified and some other information related to the contract.
  5. EOA vs. Contract: If the address is an EOA (externally-owned account) and not a contract, the “Contract” section will not appear, and you’ll mostly see transaction history, balance, and other details associated with an Ethereum address. EOA simply refers to regular Ethereum address owned by an entity and are controlled by private key.

🔥 Check this out: Build in Public

Using code size of the address

Another way you can determine whether a given address is a contract or an externally-owned account (EOA) by checking the code size of the address. If an address is a contract, its code size will be greater than zero, as contracts have bytecode associated with them, whereas EOAs do not.


pragma solidity ^0.8.0;

contract AddressChecker {
    function isContract(address _address) public view returns (bool) {
        uint256 codeSize;
        assembly {
            codeSize := extcodesize(_address)
        }
        return codeSize > 0;
    }
}

In this contract, the isContract function takes an Ethereum address as an argument and returns true if the address is a contract and false if it’s an EOA.

🔥 Check this out: Write Your First Solidity Smart Contract on Ethereum

Conclusion

Anyone can view transactions happening on blockchain at any point of time whether it is a smart contract or an external account. Knowing if the address you are interacting with is smart contract or EOA can have significant impact in certain scenarios.

Follow us on –

🔮Twitter – https://twitter.com/0xmetaschool

🔗LinkedIn – https://www.linkedin.com/company/0xmetaschool/