Data type

Solidity is a statically typed language. Developers familiar with language such as JavaScript and Python will find Solidity syntax easy to pick up. Each variable needs to specify the data type. The variable, which will always be passed by value, is called value types, it is built-in or predefined data types.

The value types in solidity are as follows:

Types

Operators

Example

Note

Bool

!, &&, ||, ==, !=

bool a = true;

The Booleans are true or false expressions.

Int (int8 to int256)

Comparison operators:

<=, <, ==, !=, >=, >,

Bit operators: &, |, ^, +, -, unary -, unary +, *, /, %, **, <<, >>

int a = 1;

Signed integer, signed of 8 up to 256 bits, in the step of 8.

Uint (uint8 to uint256)

Comparison operators: <=, <, ==, !=, >=, >

Bit operators: &, |, ^, +, -, unary -, unary +, *, /, %, **, <<, >>

uint maxAge = 100;

Unsigned  integer, unsigned of 8 up to 256 bits, in the step of 8.

Address

<=, <, ==, !=, >= ,>

address owner = msg.sender;
address myAddress = 0xE0f5206B…437b9;

Holds a 20 byte value (size of an Ethereum address).

<address>.balance

 

address.balance()

Addresses members and <indexentry content="value types, solidity:.balance">returns the balance of the address in Wei.

<address>.transfer

 

beneficiary.transfer(highestBid)

Addresses members and sends ether (in units of Wei) to an address. If the transfer operation fails, it <indexentry content="value types, solidity:.transfer">throws an exception, and all of the changes in a transaction are reverted.

<address>.send

 

msg.sender.send(amount)

Addresses members and send ether (in units of Wei) to an address. If the send operation fails, it returns false.

<address>.call

 

someAddress.call.
value(1ether)
.gas(100000) ("register", "MyName")

Executed code of another contract, returns false in the event of failure, forwards all available gas, adjustable, should be used when you need to control how much gas to forward.

<address>.delegatecall

 

, _library.delegatecall(msg.data);

Executed code of another contract, but with the state (storage) of the calling contract.

Fixed size byte array

(bytes1, bytes2, …, bytes32)

Comparison operators: <=, <, ==, !=, >=, >,

Bit operators: &, |, ^ ,~,<<, >>,

get array data :

 array[index]

uint8[5] memory traits = [1,2,3,4,5];

Fixed size byte arrays are defined using the keyword byteN, the N being any number from 1 to 32, it limits the size, it will be a lot cheaper and will save you gas.

 

 

 

 

 

 

Dynamically-sized array bytes string

 

 

 

 

 

 

 

 

/**bytes array **/
bytes32[] dynamicArray
function f() {
bytes32[] storage storageArr = dynamicArray
storageArr.length++;
}
/**string array **/
bytes32[] public names

Solidity supports a dynamically-sized byte array and a dynamically-sized UTF-8-encoded string.

Hexadecimal literals

 

hex"1AF34A"

Hexadecimal literals are prefixed with the keyword hex and are enclosed in single or double quotes.

Address literals

 

0x5eD8Cee6b63b1c6AFce

3AD7c92f4fD7E1B8fAd9F

 

It is hexadecimal literals that pass the address checksum test.

String literals

 

"Hello”

String literals are normally written with either single or double quotes.

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

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