Edited:
The method isContract
is missing. You can just validate this way.
modifier onlyNotContract() {
require(msg.sender == tx.origin);
_;
}
Read more: https://ethereum.stackexchange.com/a/14016/76945
Thanks Nulik for suggesting.
--
Prior Answer:
⚠️ Warning: there is no secure way to prevent contract from calling for now. You can be hacked. Be mindful of using this method.
However if you still need it considering the risk, isContract()
is missing from your source code. I am assuming it is from OpenZeppelin Address Library.
There are a few approaches to import,
Approach 1. You can copy the function isContract
to do like this
function isContract(address account) internal view returns (bool) {
..
}
modifier onlyNotContract() {
require(!isContract(msg.sender), "...");
_;
}
Approach 2. Or if you want the whole library, you can import and use.
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Address.sol";
Contract Sample {
using Address for address;
modifier onlyNotContract() {
require(!msg.sender.isContract(), "...");
_;
}
}