2

I've found this in ERC223 specifications:

NOTE: The recommended way to check whether the _to is a contract or an address is to assemble the code of _to. If there is no code in _to, then this is an externally owned address, otherwise it's a contract.

What does "assemble the code" in this context mean?

Or, how do some contract knows it's sending funds to a contract not externally owned account?

If msg.data (not sure if this the right object) is empty it's externally owned account?

1 Answer 1

1

There are two types of addresses in Ethereum. Externally Owned Accounts and Contracts. The difference between these two is that externally owned accounts posses a private key, but have no code attached to it. Contracts have no private key, but posses code (see web3.eth.getCode(<ADDRESS>)).

how do some contract knows it's sending funds to a contract not externally owned account?

See https://stackoverflow.com/questions/37644395/how-to-find-out-if-an-ethereum-address-is-a-contract

3
  • I know about Ethereum account types. But it's good you mention it, for folks that don't know. You partially answered my question. But I have another one related. How can my code (my smart contract deployed on blockchain, not on my private chain) know if it's dealing with externally owned account or contract account? What you have posted was if I want to extract code from some other contract into bytes variable. But what if I just want my contract to distinguish between externally owned and contract account.Has the protocol some way to know if it's contract without in line assembly you posted?
    – user9365
    Commented Feb 25, 2018 at 18:12
  • Check the update in the answer. There is a faster way. You can check the code size instead of reading all the bytes. I wasn't aware of this until now.
    – ivicaa
    Commented Feb 25, 2018 at 18:25
  • Thanks. That updated answer is what I was trying to find! :)
    – user9365
    Commented Feb 25, 2018 at 18:31

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.