Search code examples
ethereumblockchainsoliditysmartcontracts

How to find out if an Ethereum address is a contract?


An address in Solidity can be an account or a contract (or other things, such as a transaction). When I have a variable x, holding an address, how can I test if it is a contract or not?

(Yes, I've read the chapter on types in the doc)


Solution

  • Edit: Solidity has changed since this answer was first written, @manuel-aráoz has the correct answer.

    There is no way in solidity to check if an address is a contract. One of the goals of Ethereum is for humans and smart contracts to both be treated equally. This leads into a future where smart contracts interact seamlessly with humans and other contracts. It might change in the future , but for now an arbitrary address is ambiguous.