Constant state variables, unit, and functions

The value of a constant cannot change through reassignment, and it can't be redeclared after compile time. In solidity, a state variable can be declared as constant. It does not allow reassignment to blockchain data (for example, this .balance, block.blockhash), or execution data (tx.gasprice), or make calls to external contracts.

The following table out the solidity global variables and their built-in functions:

Global variables / functions

Description

msg.sender(address)

msg.sender is the address currently interacting with the contract call message.

msg.data(bytes)

msg.data is the address currently interacting with the contract complete call. The data is in bytes.

msg.value(unit)

msg.value is the address currently interacting with the number of Wei sent with message as per the contract.

msg.sig

msg.sig is the address currently interacting with the contract that returns the first four bytes of the call data.

gasleft() returns (uint256)

API to check the gas remaining.

tx.origin

API to check the sender of the transaction.

tx.gasprice

API to check the gas price of the transaction.

now

Get current unix timestamp.

block.number

API to retrieve the current block number.

block.difficulty

API to retrieve the current block difficulty.

block.blockhash(uint blockNumber) returns (bytes32)

API to get the hash of the given block; the result only returned the 256 most recent blocks.

block.gasLimit(unit)

API to get the current block gas limit.

block.coinbase ()

Returns the current block miner's address.

keccak256(...);

Returns (bytes32) compute the Ethereum-SHA-3 (Keccak-256) hash of the (tightly packed) arguments.

sha3(...)

Returns (bytes32): an alias to keccak256.

assert(bool condition)

assert can be used to check for conditions. It indicates something that should never be false under any circumstances. Furthermore, assert uses the 0xfe opcode to cause an error condition.

require(bool condition)

The require function should be used to ensure valid conditions. It can return false when the user enters something inappropriate. Furthermore, require() uses the 0xfd opcode to cause an error condition.

revert()

revert will still undo all state changes.

<address>.balance

It checks the balance of the address in Wei (uint256).

<address>.send(uint256 amount) returns (bool)

API sends the amount of Wei to address and returns false in the event failure.

<address>.transfer(uint256 amount)

API transfer the amount of Wei to the address, and throws error when transfer fails.

this

The current contract, explicitly convertible to address.

super

The contract one level higher in the inheritance hierarchy.

selfdestruct(address recipient)

self-destruct will destroy the current contract, and storage associated with it is removed from the Ethereum's world state.

suicide(address recipient)

An alias to self-destruct.

 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.28.80