# solidity的函数修饰符 **Published by:** [leishen](https://paragraph.com/@ldplxp/) **Published on:** 2022-05-17 **URL:** https://paragraph.com/@ldplxp/solidity ## Content 修饰符是可以在一个函数调用之前或之后运行的代码。 有三种形式:基础修饰符,带参数,夹在中间的(sandwich) 修饰符可以用来: 限制访问 验证输入 防止重入黑客攻击 contract FunctionModifier{ bool public paused; uint public count; modifier whenNotPaused(){ require(!paused, "the contract is paused"); // _;的意思是返回主函数 _; } modifier cap(uint _x){ require(_x < 100, "X >= 100"); _; } modifier sandwich(){ count += 10; _; count *= 2; } // 函数修饰符可以用一大堆 function incBy(uint _x) external whenNotPaused cap(_x) sandwich{ count += _x; } } ## Publication Information - [leishen](https://paragraph.com/@ldplxp/): Publication homepage - [All Posts](https://paragraph.com/@ldplxp/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@ldplxp): Subscribe to updates - [Twitter](https://twitter.com/binbinlee4): Follow on Twitter