Solidity数据类型

简单数据类型:bool值true或者false

                            整形uint无符号整数,int有符号整数,ufixed和fixed代表分数

                            address可以存储最大20字节值(十六进制表示),用于存储以太坊地址。属性balance检测地址余额,send用于向地址发送以太币。

数组类型:generic数组类型,普通数组类型

                   byte字节数组类型,byte1,byte2...

字符串类型:byte创建原始字符串

                      string创建UTF-8字符串

结构类型:struct类似于C语言struct

枚举类型:enum

mapping类型:是一个hash表,只存在storage中作为状态变量声明

var 申明状态变量

全局可用变量:

区块和交易的属性

  • block.blockhash(uint blockNumber) returns (bytes32):返回给定区块号的哈希值,只支持最近256个区块,且不包含当前区块。
  • block.coinbase (address): 当前块矿工的地址。
  • block.difficulty (uint):当前块的难度。
  • block.gaslimit (uint):当前块的gaslimit。
  • block.number (uint):当前区块的块号。
  • block.timestamp (uint): 当前块的Unix时间戳(从1970/1/1 00:00:00 UTC开始所经过的秒数)
  • msg.data (bytes): 完整的调用数据(calldata)。
  • msg.gas (uint): 当前还剩的gas。
  • msg.sender (address): 当前调用发起人的地址。
  • msg.sig (bytes4):调用数据(calldata)的前四个字节(例如为:函数标识符)。
  • msg.value (uint): 这个消息所附带的以太币,单位为wei。
  • now (uint): 当前块的时间戳(block.timestamp的别名)
  • tx.gasprice (uint) : 交易的gas价格。
  • tx.origin (address): 交易的发送者(全调用链)   

地址类型相关

  • <address>.balance (uint256):Address的余额,以wei为单位。

  • <address>.transfer(uint256 amount):发送给定数量的ether到某个地址,以wei为单位。失败时抛出异常。

  • <address>.send(uint256 amount) returns (bool):发送给定数量的ether到某个地址,以wei为单位, 失败时返回false。

  • <address>.call(...) returns (bool):发起底层的call调用。失败时返回false。

  • <address>.callcode(...) returns (bool):发起底层的callcode调用,失败时返回false。

  • <address>.delegatecall(...) returns (bool):发起底层的delegatecall调用,失败时返回false。                 

合约相关

  • this(当前合约的类型):表示当前合约,可以显式的转换为Address
  • selfdestruct(address recipient):销毁当前合约,并把它所有资金发送到给定的地址。
  • suicide(address recipient):selfdestruct的别名

猜你喜欢

转载自blog.csdn.net/xinsuiqingfeng/article/details/81805244