Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the function modifire in solidity

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to use the function modifire in solidity. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

Function modifire

The function modifire is used to perform some initialization before the function is executed. For example, the judgment of authority.

Modifire can play the role of encapsulation and simplify the writing of code.

Definition of modifire

Add the modifire keyword, enter the statement inside the curly braces, and underscore _ at the end.

one

two

three

four

Modifier function name () {

Statement

_

}

Modifire usage

Modifire is used by adding the name of modifer between the function modifier and the return value, as shown below

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

Modifier OnlyOwner () {

Require (msg.sender==owner)

_

}

Function changeIt (uint _ num) public OnlyOwner {

A = _ num

}

Function getIt () view public OnlyOwner returns (address) {

Return owner

}

For the functions changeIt and getIt with modifire added to it.

The execution flow of the changeIt function is to first execute require (msg.sender==owner), and then execute all the statements inside the function body, in this case a = _ num.

So, the underscore in modifier is actually all the statements within the body of the function that you refer to. The statements in modifire are executed before the internal code of the function is executed.

The above is all the contents of the article "how to use modifire in solidity". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report