Chuyển đến nội dung chính

Bài đăng

Đang hiển thị bài đăng từ Tháng 6, 2023

Solidity Libraries Restrictions

  Solidity have certain restrictions on use of a Library: Library functions can be called directly if they do not modify the state. That means pure or view functions only can be called from outside the library . Library can not be destroyed as it is assumed to be stateless. A Library cannot have state variables . A Library cannot inherit from any element. A Library cannot be inherited.

Fallback function

  Fallback function is a special function available to a contract. It has following features − It is called when a non-existent function is called on the contract. It is required to be marked external. It has no name. It has no arguments It can not return any thing. It can be defined one per contract. If not marked payable, it will throw exception if contract receives plain ether without data.

Pure and View Function DEV by Solidity

View functions ensure that they will not modify the state ,  compiler will throw warning in such cases: Modifying state variables. Emitting events. Creating other contracts. Using selfdestruct. Sending Ether via calls. Calling any function which is not marked view or pure. Using low-level calls. Using inline assembly containing certain opcodes Pure functions ensure that they not read or modify the state ,  compiler will throw warning in such cases. Reading state variables. Accessing address(this).balance or <address>.balance. Accessing any of the special variable of block, tx, msg (msg.sig and msg.data can be read). Calling any function not marked pure. Using inline assembly that contains certain opcodes.

[Blockchain] Globally variables

Special variables are globally available variables and provides information about the blockchain. Following is the list of special variables: Sr.No. Special Variable & Description 1 blockhash(uint blockNumber) returns (bytes32) Hash of the given block - only works for 256 most recent, excluding current, blocks. 2 block.coinbase (address payable) Current block miner's address. 3 block.difficulty (uint) current block difficulty. 4 block.gaslimit (uint) Current block gaslimit. 5 block.number (uint) Current block number. 6 block.timestamp Current block timestamp as seconds since unix epoch. 7 gasleft() returns (uint256) Remaining gas. 8 msg.data (bytes calldata) Complete calldata. 9 msg.sender (address payable) Sender of the message (current call). 10 msg.sig (bytes4) First four bytes of the calldata (i.e. function identifier) 11 msg.value (uint) Number of wei sent with the message. 12 now (uint) Current block timestamp (alias for block.timestamp). 13 tx.gasprice (uint) Gas price o