Cheatsheet
ترتيب أسبقية المشغلين
.. 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>-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 tofunctionPointerwith the arguments found in the tuple. Performs a full type-check, ensuring the types match the function signature. Result equalsabi.encodeWithSelector(functionPointer.selector, (...))abi.encodeWithSignature(string memory signature, ...) returns (bytes memory): Equivalent toabi.encodeWithSelector(bytes4(keccak256(bytes(signature)), ...)bytes.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>block.basefee(uint): current block’s base fee (EIP-3198 <https://eips.ethereum.org/EIPS/eip-3198>_ andEIP-1559 <https://eips.ethereum.org/EIPS/eip-1559>_)block.chainid(uint): current chain idblock.coinbase(address payable): current block miner’s addressblock.difficulty(uint): current block difficultyblock.gaslimit(uint): current block gaslimitblock.number(uint): current block numberblock.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)assert(bool condition): abort execution and revert state changes if condition isfalse(use for internal error)require(bool condition): abort execution and revert state changes if condition isfalse(use for malformed input or error in external component)require(bool condition, string memory message): abort execution and revert state changes if condition isfalse(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 stringblockhash(uint blockNumber) returns (bytes32): hash of the given block - only works for 256 most recent blockskeccak256(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) % kwhere the addition is performed with arbitrary precision and does not wrap around at2**256. Assert thatk != 0starting from version 0.5.0.mulmod(uint x, uint y, uint k) returns (uint): compute(x * y) % kwhere the multiplication is performed with arbitrary precision and does not wrap around at2**256. Assert thatk != 0starting from version 0.5.0.this(current contract’s type): the current contract, explicitly convertible toaddressoraddress payablesuper: the contract one level higher in the inheritance hierarchyselfdestruct(address payable recipient): destroy the current contract, sending its funds to the given address<address>.balance(uint256): balance of the :ref:addressin Wei<address>.code(bytes memory): code at the :ref:address(can be empty)<address>.codehash(bytes32): the codehash of the :ref:address<address payable>.send(uint256 amount) returns (bool): send given amount of Wei to :ref:address, returnsfalseon failure<address payable>.transfer(uint256 amount): send given amount of Wei to :ref:address, throws on failuretype(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 typeT, see :ref:Type Information<meta-type>.type(T).max(T): the maximum value representable by the integer typeT, see :ref:Type Information<meta-type>.
محددات رؤية الوظيفة
| |
public: مرئي خارجيا وداخلية (creates a :ref:getter function<getter-functions>لمتغيرات التخزين/الحالة)private: مرئي فقط في العقد الحاليexternal: لا يمكن تسمى الرسائل إلا مرئيًا خارجيًا فقط (فقط للوظائف) - أي فقط (viathis.func)internal: مرئي فقط داخليًا
الصفات التعريفية
purefor functions: لا يسيطر على التعديل أو الوصول إلى الدولة.viewfor functions: لا يسيطر تعديل الدولة.payablefor functions: يسمح لهم بتلقي الأثير مع مكالمة.constantfor state variables: لا تسمح المهمة (باستثناء التهيئة) ، لا تشغل فتحة التخزين.immutablefor state variables: يسمح بالضبط بمهمة واحدة في وقت البناء وهي ثابتة بعد ذلك.يتم تخزينه في الكود.anonymousfor events: لا تخزن توقيع الحدث كموضوع.indexedfor event parameters: يخزن المعلمة كموضوع.virtualfor functions and modifiers: يسمح بتغيير سلوك الوظيفة أو المعدل في العقود المشتقة.override: ينص على أن هذه الوظيفة أو المعدل أو متغير الحالة العامة تغير سلوك دالة أو تعديل في قاعدةcontract.
الكلمات الرئيسية المحجوزة
هذه الكلمات الرئيسية مخصصة في صلابة.قد يصبحون جزءًا من بناء الجملة في المستقبل:
after, alias, apply, auto, byte, case, copyof, default,
define, final, implements, in, inline, let, macro, match,
mutable, null, of, partial, promise, reference, relocatable,
sealed, sizeof, static, supports, switch, typedef, typeof,
var.
