Skip to content

Latest commit

 

History

History
45 lines (31 loc) · 1012 Bytes

视图和纯函数.md

File metadata and controls

45 lines (31 loc) · 1012 Bytes

视图和纯函数

Pure和View函数都是只读函数,它们不能向区块链写入任何内容。 纯函数不读取任何状态或全局变量。 视图函数可以读取状态变量、全局变量和调用内部函数。

# @version ^0.3.7

num: public(uint256)

# Pure functions does not read any state or global variables
@external
@pure
def pureFunc(x: uint256) -> uint256:
    return x


# View functions might read state or global state, or call an internal function
@external
@view
def viewFunc(x: uint256) -> bool:
    return x > self.num


@external
@pure
def sum(x: uint256, y: uint256, z: uint256) -> uint256:
    return x + y + z


@external
@view
def addNum(x: uint256) -> uint256:
    return x + self.num

关注我们

Yanbo的TwitterWeb3Club的Twitter

加入Web3Club 官方讨论群:YanboTravelAllWorld(微信号)

加入我们