简体   繁体   中英

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?

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 {}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM