知乎專欄 | 多維度架構 | | | 微信號 netkiller-ebook | | | QQ群:128659835 請註明“讀者” |
address public minter; string name; int num; uint constant x = 32**22 + 8; string constant text = "abc"; bytes32 constant myHash = keccak256("abc"); uint256 ticket = 1 ether;
變數賦值
pragma solidity ^0.4.25; contract C { uint[] data; function f() public view returns (uint, bool, uint) { return (7, true, 2); } function g() public { // 聲明和分配變數。 明確指定類型是不可能的。 var (x, b, y) = f(); // 分配給一個預先存在的變數。 (x, y) = (2, 7); // 互換值的常用技巧對於非價值存儲類型不起作用。 (x, y) = (y, x); // 組件可以省略(也可以用於變數聲明)。 // 如果元組以空組件結束,其餘的值將被丟棄。 (data.length,) = f(); // 設置長度為 7 // 在左邊也可以做同樣的事情。 (,data[3]) = f(); // Sets data[3] to 2 // 組件只能在作業的左側排除,但有一個例外: (x,) = (1,); // (1,) 是指定1元組元的唯一方法,因為(1)等於1。 } }
block.blockhash(uint blockNumber) returns (bytes32): hash of the given block - only works for 256 most recent blocks block.coinbase (address): current block miner’s address block.difficulty (uint): current block difficulty block.gaslimit (uint): current block gaslimit block.number (uint): current block number block.timestamp (uint): current block timestamp msg.data (bytes): complete calldata msg.gas (uint): remaining gas msg.sender (address): sender of the message (current call) msg.value (uint): number of wei sent with the message now (uint): current block timestamp (alias for block.timestamp) tx.gasprice (uint): gas price of the transaction 6.4. Solidity in Depth 99Solidity Documentation, 0.4.10 tx.origin (address): sender of the transaction (full call chain) revert(): abort execution and revert state changes keccak256(...) returns (bytes32): compute the Ethereum-SHA-3 (Keccak-256) hash of the (tightly packed) arguments sha3(...) returns (bytes32): an alias to keccak256() sha256(...) returns (bytes32): compute the SHA-256 hash of the (tightly packed) arguments ripemd160(...) returns (bytes20): compute the RIPEMD-160 hash of the (tightly packed) arguments ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address): recover address associated with the public key from elliptic curve signature, return zero on error addmod(uint x, uint y, uint k) returns (uint): compute (x + y) % k where the addition is performed with arbitrary precision and does not wrap around at 2**256 mulmod(uint x, uint y, uint k) returns (uint): compute (x * y) % k where the multiplication is performed with arbitrary precision and does not wrap around at 2**256 this (current contract’s type): the current contract, explicitly convertible to address super: the contract one level higher in the inheritance hierarchy selfdestruct(address recipient): destroy the current contract, sending its funds to the given address .balance (uint256): balance of the Address in Wei .send(uint256 amount) returns (bool): send given amount of Wei to Address, returns false on failure .transfer(uint256 amount): send given amount of Wei to Address, throws on failure
block.blockhash(uint blockNumber) returns (bytes32): 某個區塊的區塊鏈hash值
block.coinbase (address): 當前區塊的挖礦地址
block.difficulty (uint): 當前區塊的難度
block.gaslimit (uint): 當前區塊的gaslimit
block.number (uint): 當前區塊編號
block.timestamp (uint): 當前區塊時間戳
msg.data (bytes): 參數數據
msg.gas (uint): 剩餘的gas
msg.sender (address): 當前發送消息的地址,執行合約的地址。
msg.sig (bytes4): 方法ID
msg.value (uint): 執行合約時,轉賬的eth數量,以wei為單位。
now (uint): 時間戳,等價于block.timestamp (uint)
tx.gasprice (uint): 交易的gas單價
tx.origin (address):交易發送地址