Check for contracts using Address.sol
In your contract, when you need to confirm whether an address is a contract or an EOA, you can use the Address.sol library. This library provides a function, isContract(), which checks the address and finds the byte size of the contract attached to that address. If the code size is greater than zero, that means it is a contract.
However, this is not the recommended way to check whether an address is a contract or not. During the contract's constructor execution, a contract isn't treated as a contract. Thus, if you call the isContract() function while a contract is executing its constructor, then the function would return false.
The OpenZeppelin contract present at Chapter09/openzeppelin-solidity/contracts/utils/Address.sol ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access