.. index:: operator; precedence
.. index:: assert, block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, gas price, origin, revert, require, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, codehash, send
abi.decode(bytes memory encodedData, (...)) returns (...)
: :ref:`ABI <ABI>`- 对提供的数据进行解码,类型在括号中作为第二个参数给出。 示例:(uint a, uint[2] memory b, bytes memory c) = abi.decode(data, (uint, uint[2], bytes))
abi.encode(...) returns (bytes memory)
: :ref:`ABI <ABI>` - 对给定的参数进行编码abi.encodePacked(...) returns (bytes memory)
: 给指定的参数执行 :ref:`packed encoding <abi_packed_mode>` , 请注意,这种编码可能会有歧义!(参数和编码可能出现多对一的情况)abi.encodeWithSelector(bytes4 selector, ...) returns (bytes memory)
: :ref:`ABI <ABI>`- 为给定的 4 字节选择器和随后的参数进行编码。abi.encodeCall(function functionPointer, (...)) returns (bytes memory)
: 对functionPointer
指向的函数调用及元组中的参数进行编码,执行完整的类型检查,确保类型与函数签名相符。结果等于abi.encodeWithSelector(functionPointer.selector, (...))
abi.encodeWithSignature(string memory signature, ...) returns (bytes memory)
: 等于abi.encodeWithSelector(bytes4(keccak256(bytes(signature)), ...)
bytes.concat(...) returns (bytes memory)
: :ref:`将可变数量的参数串联成一个字节数组<bytes-concat>`string.concat(...) returns (string memory)
: :ref:`将可变数量的参数串联成一个字符串<string-concat>`block.basefee
(uint
): 当前区块的基础gas fee , 参考 (EIP-3198 和 EIP-1559)block.chainid
(uint
): 当前 chain idblock.coinbase
(address payable
): 当前区块矿工的地址block.difficulty
(uint
): 当前区块难度block.gaslimit
(uint
): 当前区块gaslimitblock.number
(uint
): 当前区块号block.timestamp
(uint
): 当前区块时间戳(以Unix epoch依赖的秒数)gasleft() returns (uint256)
: 剩余 gasmsg.data
(bytes
): 完整的 calldata 数据msg.sender
(address
): 消息调用者 (当前调用)msg.sig
(bytes4
): calldata的前 4 个字节 (如:函数签名)msg.value
(uint
): 与消息一起发送的以太币(wei为单位)tx.gasprice
(uint
): 交易的gas 价格tx.origin
(address
): 交易的发起者 (完整的调用链下,最初的发起者)assert(bool condition)
: 如果条件为false
, 终止执行并回退状态改变 (用于内部错误)require(bool condition)
: 如果条件为false
, 终止执行并回退状态改变 (用于检查错误输入,或外部组件的错误)require(bool condition, string memory message)
: 如果条件为false
, 终止执行并回退状态改变 (用于检查错误输入,或外部组件的错误),同时提供错误信息。revert()
: 终止执行并回退状态改变revert(string memory message)
: 终止执行并回退状态改变,同时提供错误解释信息。blockhash(uint blockNumber) returns (bytes32)
: 指定块的区块hash - 仅最近 256 个区块有效keccak256(bytes memory) returns (bytes32)
: 计算输入参数的 Keccak-256 哈希sha256(bytes memory) returns (bytes32)
: 计算输入参数的 SHA-256 哈希ripemd160(bytes memory) returns (bytes20)
: 计算输入参数的 RIPEMD-160 哈希ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address)
: 从椭圆曲线签名中恢复出与公钥关联的地址,出错时返回零。addmod(uint x, uint y, uint k) returns (uint)
: 计算(x + y) % k
,其中加法以任意精度执行,不会在2**256
处溢出。从 0.5.0 开始要求k != 0
。mulmod(uint x, uint y, uint k) returns (uint)
: 计算(x * y) % k
,其中乘法以任意精度执行,不会在2**256
处溢出。从 0.5.0 开始要求k != 0
。this
(current contract's type): 当前合约,可以显式转换为address
或address payable
super
: 继承树的上层合约selfdestruct(address payable recipient)
: 销毁合约,把合约的剩余资金(以太币)发送到指定的地址。<address>.balance
(uint256
): :ref:`address` 的余额,以 wei 为单位<address>.code
(bytes memory
): :ref:`address` 的代码 (可以为空)<address>.codehash
(bytes32
): :ref:`address` 的代码 hash<address payable>.send(uint256 amount) returns (bool)
: 发送amount
数量(单位wei)的以太币到 :ref:`address` , 失败返回false
。<address payable>.transfer(uint256 amount)
: 发送amount
数量(单位wei)的以太币到 :ref:`address` , 失败时抛出异常。type(C).name
(string
): 合约的名称type(C).creationCode
(bytes memory
): 合约的创建字节码,参考 :ref:`类型信息<meta-type>`.type(C).runtimeCode
(bytes memory
): 合约的运行时字节码,参考 :ref:`类型信息<meta-type>`.type(I).interfaceId
(bytes4
): 包含给定接口的EIP-165接口标识符 , 参考 :ref:`类型信息<meta-type>`.type(T).min
(T
): 所在整型T
的最小值, 参考 :ref:`类型信息<meta-type>`.type(T).max
(T
): 所在整型T
的最大值, 参考 :ref:`类型信息<meta-type>`.
Note
当合约在链外而不是在包含的交易的区块中下被执行时,你不应该假定 block.*
和 tx.*
是某特定区块或交易的值。这些值是由执行合约的EVM实现提供的,其值可以是任意的。
.. index:: visibility, public, private, external, internal
function myFunction() <visibility specifier> returns (bool) {
return true;
}
public
: visible externally and internally (creates a :ref:`getter function<getter-functions>` for storage/state variables)private
: only visible in the current contractexternal
: only visible externally (only for functions) - i.e. can only be message-called (viathis.func
)internal
: only visible internally
.. index:: modifiers, pure, view, payable, constant, anonymous, indexed
pure
for functions: Disallows modification or access of state.view
for functions: Disallows modification of state.payable
for functions: Allows them to receive Ether together with a call.constant
for state variables: Disallows assignment (except initialisation), does not occupy storage slot.immutable
for state variables: Allows exactly one assignment at construction time and is constant afterwards. Is stored in code.anonymous
for events: Does not store event signature as topic.indexed
for event parameters: Stores the parameter as topic.virtual
for functions and modifiers: Allows the function's or modifier's behaviour to be changed in derived contracts.override
: States that this function, modifier or public state variable changes the behaviour of a function or modifier in a base contract.