docs/cheatsheet.rst
Cheatsheet
.. index:: operator;precedence
.. include:: types/operator-precedence-table.rst
.. index:: abi;decode, abi;encode, abi;encodePacked, abi;encodeWithSelector, abi;encodeCall, abi;encodeWithSignature
abi.decode(bytes memory encodedData, (...)) returns (...): :ref:ABI <ABI>-decodes
the provided data. The types are given in parentheses as second argument.
Example: (uint a, uint[2] memory b, bytes memory c) = abi.decode(data, (uint, uint[2], bytes))abi.encode(...) returns (bytes memory): :ref:ABI <ABI>-encodes the given argumentsabi.encodePacked(...) returns (bytes memory): Performs :ref:packed encoding <abi_packed_mode> of
the given arguments. Note that this encoding can be ambiguous!abi.encodeWithSelector(bytes4 selector, ...) returns (bytes memory): :ref:ABI <ABI>-encodes
the given arguments starting from the second and prepends the given four-byte selectorabi.encodeCall(function functionPointer, (...)) returns (bytes memory): ABI-encodes a call to functionPointer with the arguments found in the
tuple. Performs a full type-check, ensuring the types match the function signature. Result equals abi.encodeWithSelector(functionPointer.selector, ...)abi.encodeWithSignature(string memory signature, ...) returns (bytes memory): Equivalent
to abi.encodeWithSelector(bytes4(keccak256(bytes(signature))), ...).. index:: bytes;concat, string;concat
bytes and stringbytes.concat(...) returns (bytes memory): :ref:Concatenates variable number of arguments to one byte array<bytes-concat>
string.concat(...) returns (string memory): :ref:Concatenates variable number of arguments to one string array<string-concat>
.. index:: address;balance, address;codehash, address;send, address;code, address;transfer
address<address>.balance (uint256): balance of the :ref:address in Wei<address>.code (bytes memory): code at the :ref:address (can be empty)<address>.codehash (bytes32): the codehash of the :ref:address<address>.call(bytes memory) returns (bool, bytes memory): issue low-level CALL with the given payload,
returns success condition and return data<address>.delegatecall(bytes memory) returns (bool, bytes memory): issue low-level DELEGATECALL with the given payload,
returns success condition and return data<address>.staticcall(bytes memory) returns (bool, bytes memory): issue low-level STATICCALL with the given payload,
returns success condition and return data<address payable>.send(uint256 amount) returns (bool): send given amount of Wei to :ref:address,
returns false on failure (deprecated)<address payable>.transfer(uint256 amount): send given amount of Wei to :ref:address, throws on failure (deprecated).. index:: blockhash, blobhash, block, block;basefee, block;blobbasefee, block;chainid, block;coinbase, block;difficulty, block;gaslimit, block;number, block;prevrandao, block;timestamp .. index:: gasleft, msg;data, msg;sender, msg;sig, msg;value, tx;gasprice, tx;origin
blockhash(uint blockNumber) returns (bytes32): hash of the given block - only works for 256 most recent blocksblobhash(uint index) returns (bytes32): versioned hash of the index-th blob associated with the current transaction.
A versioned hash consists of a single byte representing the version (currently 0x01), followed by the last 31 bytes
of the SHA256 hash of the KZG commitment (EIP-4844 <https://eips.ethereum.org/EIPS/eip-4844>_).
Returns zero if no blob with the given index exists.block.basefee (uint): current block's base fee (EIP-3198 <https://eips.ethereum.org/EIPS/eip-3198>_ and EIP-1559 <https://eips.ethereum.org/EIPS/eip-1559>_)block.blobbasefee (uint): current block's blob base fee (EIP-7516 <https://eips.ethereum.org/EIPS/eip-7516>_ and EIP-4844 <https://eips.ethereum.org/EIPS/eip-4844>_)block.chainid (uint): current chain idblock.coinbase (address payable): current block miner's addressblock.difficulty (uint): current block difficulty (EVM < Paris). For other EVM versions it behaves as a deprecated alias for block.prevrandao that will be removed in the next breaking releaseblock.gaslimit (uint): current block gaslimitblock.number (uint): current block numberblock.prevrandao (uint): random number provided by the beacon chain (EVM >= Paris) (see EIP-4399 <https://eips.ethereum.org/EIPS/eip-4399>_ )block.timestamp (uint): current block timestamp in seconds since Unix epochgasleft() returns (uint256): remaining gasmsg.data (bytes): 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).. index:: assert, require, revert
assert(bool condition): abort execution and revert state changes if condition is false (use for internal error)require(bool condition): abort execution and revert state changes if condition is false (use
for malformed input or error in external component)require(bool condition, string memory message): abort execution and revert state changes if
condition is false (use for malformed input or error in external component). Also provide error message.revert(): abort execution and revert state changesrevert(string memory message): abort execution and revert state changes providing an explanatory string.. index:: cryptography, keccak256, sha256, ripemd160, ecrecover, addmod, mulmod, erc7201
keccak256(bytes memory) returns (bytes32): compute the Keccak-256 hash of the inputsha256(bytes memory) returns (bytes32): compute the SHA-256 hash of the inputripemd160(bytes memory) returns (bytes20): compute the RIPEMD-160 hash of the inputecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address): recover address associated with
the public key from elliptic curve signature, return zero on erroraddmod(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. Assert that k != 0 starting from version 0.5.0.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. Assert that k != 0 starting from version 0.5.0.erc7201(string memory id) returns (uint): compute the base slot of an erc7201 storage namespace.
Can be used in compile time context... index:: this, super, selfdestruct
this (current contract's type): the current contract, explicitly convertible to address or address payablesuper: a contract one level higher in the inheritance hierarchyselfdestruct(address payable recipient): send all funds to the given address and (only on EVMs before Cancun or when invoked within the transaction creating the contract) destroy the contract... index:: type;name, type;creationCode, type;runtimeCode, type;interfaceId, type;min, type;max
type(C).name (string): the name of the contracttype(C).creationCode (bytes memory): creation bytecode of the given contract, see :ref:Type Information<meta-type>.type(C).runtimeCode (bytes memory): runtime bytecode of the given contract, see :ref:Type Information<meta-type>.type(I).interfaceId (bytes4): value containing the EIP-165 interface identifier of the given interface, see :ref:Type Information<meta-type>.type(T).min (T): the minimum value representable by the integer type T, see :ref:Type Information<meta-type>.type(T).max (T): the maximum value representable by the integer type T, see :ref:Type Information<meta-type>... index:: visibility, public, private, external, internal
.. code-block:: solidity :force:
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 (via this.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 initialization), does not occupy storage slot.immutable for state variables: Allows assignment at construction time and is constant when deployed. 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
behavior to be changed in derived contracts.override: States that this function, modifier or public state variable changes
the behavior of a function or modifier in a base contract.