Modifier
Solidityपरिभाषा
Modifier एक reusable code block है जो function behavior को modify करता है। Modifiers typically access control, validation और preconditions check करने के लिए use होते हैं। Underscore (_) placeholder function body के execution को represent करता है।
English version
Modifier is a reusable code block that modifies function behavior. Modifiers are typically used for access control, validation and precondition checks. The underscore (_) placeholder represents the execution of the function body.
Code Example
// Modifier de contrôle d'accès
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_; // Exécute la fonction
}
// Modifier avec paramètre
modifier costs(uint price) {
require(msg.value >= price, "Insufficient ETH");
_;
}
// Utilisation
function restricted() public onlyOwner {
// Seul le owner peut appeler
}संबंधित पेज
Solingo पर इस concept को practice करें
Modifier को interactive exercises और integrated IDE के साथ master करें।
मुफ्त में शुरू करें