Search code examples
functioncallsoliditycontract

How do I make a function that is called on every contract call? – Solidity


I need to make a function that will be called each time someone called my contract. And I need to do it without using modifiers because there are many functions in my contract and I use third-party contracts.

How can I do it?


Solution

  • You can inherit third-party contracts and make a new child contract and then modify each function with a modifier you defined in the child contract, that's the only way to do.

    Example:

    Contract ThirdParty {
        address owner;
    
        function f() public {}
    }
    
    
    Contract Child is ThirdParty {
    
        modifier onlyOwner {
            require(msg.sender == owner);
            _;
        }
    
        function f() public onlyOwner {}
    }