Global Variables
Block and Transaction Properties
blockhash(uint blockNumber) returns (bytes32): hash of the given block whenblocknumberis one of the 256 most recent blocks; otherwise returns zeroblock.basefee (uint): current block’s base feeblock.chainid (uint): current chain idblock.coinbase (address payable): current block miner’s addressblock.gaslimit (uint): current block gaslimitblock.number (uint): current block numberblock.timestamp (uint): current block timestamp as seconds since unix epochgasleft() returns (uint256): remaining gasmsg.data (bytes calldata): complete calldatamsg.sender (address): sender of the message (current call)msg.sig (bytes4): first four bytes of the calldata (i.e. function identifier)msg.value (uint): number of wei sent with the messagetx.gasprice (uint): gas price of the transactiontx.origin (address): sender of the transaction (full call chain)
Error handling
assert(bool condition): causes a Panic error and thus state change reversion if the condition is not met - to be used for internal errors.require(bool condition): reverts if the condition is not met - to be used for errors in inputs or external components.require(bool condition, string memory message): reverts if the condition is not met - to be used for errors in inputs or external components. Also provides an error message.revert(): abort execution and revert state changesrevert(string memory reason): abort execution and revert state changes, providing an explanatory string
Members of Address Types
<address>.balance (uint256): balance of the Address in Wei<address>.code (bytes memory): code at the Address (can be empty)<address>.codehash (bytes32): the codehash of the Address<address payable>.transfer(uint256 amount): send given amount of Wei to Address, reverts on failure, forwards 2300 gas stipend, not adjustable<address payable>.send(uint256 amount) returns (bool): send given amount of Wei to Address, returns false on failure, forwards 2300 gas stipend, not adjustable<address>.call(bytes memory) returns (bool, bytes memory): issue low-level CALL with the given payload, returns success condition and return data, forwards all available gas, adjustable<address>.delegatecall(bytes memory) returns (bool, bytes memory): issue low-level DELEGATECALL with the given payload, returns success condition and return data, forwards all available gas, adjustable<address>.staticcall(bytes memory) returns (bool, bytes memory): issue low-level STATICCALL with the given payload, returns success condition and return data, forwards all available gas, adjustable
Contract-related keywords
this: The current contract, explicitly convertible to Addresssuper: A contract one level higher in the inheritance hierarchyselfdestruct(address payable recipient): Destroy the current contract, sending its funds to the given Address and end execution. Note that selfdestruct has some peculiarities inherited from the EVM:the receiving contract’s receive function is not executed.
the contract is only really destroyed at the end of the transaction and revert s might “undo” the destruction.
Last updated