Let's say, I've a function defined on contract and anyone can call that function(a user, a different contract etc.).

Is there a way to identify within that function if it is a contract address or a user address in solidity? And if it is a contract, is it possible to identify the type of the contract?

Thanks in advance!

1 Answer 1


If tx.origin == msg.sender, then you know the call is coming from a "user address". If not, then it is coming from a contract.

Note that this is not guaranteed to be true forever, and it probably isn't a good idea to even make a distinction between "user" and contract accounts in your code; the long term plan for Ethereum is to eliminate this distinction entirely, and have all accounts be contracts (which may behave just like user acounts).

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.