6

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

4

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).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.