a186r avatar

solidity中的函数修饰符

a186r

Published: 09 Apr 2018 › Updated: 09 Apr 2018

solidity中的函数修饰符

有决定函数何时和被谁调用的可见性修饰符,private(只能被合约内部调用);internal(就像private,但是它也能被继承的合约调用);external(只能从合约外部调用);public(可以在任何地方调用,无论内部还是外部)。

还有状态修饰符,告诉我们函数如何和区块链交互,view(我们运行这个函数不会更改和保存任何数据);pure(我们的函数不但不会往区块链写数据,它甚至不从区块链读取数据)。这两种修饰符在被从合约外部调用的时候都不话费任何gas(但是它们在被内部其他函数调用的时候会耗费gas)。

我们还有自定义的modifiers,我们可以自定义其对函数的约束逻辑。

这些函数修饰符可以同时作用于一个函数上:

function test() external view oneModifier anotherModifier

Leave solidity中的函数修饰符 to:

Written by

Read more #solidity posts


Best Posts From a186r

We have not curated any of a186r's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From a186r