envoy1084
/
30-Days-of-Solidity
30 Days of Solidity step-by-step guide to learn Smart Contract Development.
WARNING: This repository is currently undergoing updates and revisions to incorporate the latest information and advancements in Solidity programming. Please be advised that the content may not be up-to-date or accurate during this time. We expect the updates to be completed within the next 30 days, and appreciate your patience during this process. Thank you for your understanding.
Contents
- Day 1 - Licenses and Pragma
- Day 2 - Comments
- Day 3 - Initializing Basic Contract
- Day 4 - Variables and Scopes
- Day 5 - Operators
- Day 6 - Types
- Day 7 - Functions
- Day 8 - Loops
- Day 9 - Decision Making
- Day 10 - Arrays
- Day 11 - Array Operations
- Day 12 - Enums
- Day 13 - Structs
- Day 14 - Mappings
- Day 15 - Units
- Day 16 - Require Statement
- Day 17 - Assert Statement
- Day 18 - Revert Statement
- Day 19 - Function Modifiers
- Day 20…
This is Day 6 of 30 in Solidity Series
Today I Learned About Data Types in Solidity.
Data Types
Solidity offers the programmer a rich assortment of built-in as well as user defined data types. Following table lists down seven basic C++ data types −
| Type | Keyword | Values |
|---|---|---|
| Boolean | bool | true/false |
| Integer | int/uint | Signed and unsigned integers of varying sizes. |
| Integer | int8 to int256 | Signed int from 8 bits to 256 bits. int256 is the same as int. |
| Integer | uint8 to uint256 | Unsigned int from 8 bits to 256 bits. uint256 is the same as uint. |
| Fixed Point Numbers | fixed/ufixed | Signed and unsigned fixed point numbers of varying sizes. |
| Fixed Point Numbers | fixedMxN | Signed fixed point number where M represents number of bits taken by type and N represents the decimal points. M should be divisible by 8 and goes from 8 to 256. N can be from 0 to 80. fixed is same as fixed128x18. |
| Hexadecimal | address | Holds a 20 byte value (size of an Ethereum address). |
example -
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract MyTypes {
bool myBool = true; // if bool value is not specified then it is false by default
// Unsigned Integers - can only take 0 or positive values range = 0 - (2^n - 1)
uint8 myUint8 = 84; // 0 - 255
uint16 myUint16 = 1458; // 0 - (2^16 -1)
uint256 myUint256 = 47452848525; // uint goes from 8 to 256 taking steps of 8 and can hold max number which is equal to ( 2^n -1 )
// Signed Integers - can take negative as well as positive values Range = (-2^(n-1),2^n - 1)
int8 myInt8 = -114; // -128 - 255
int16 myInt16 = -1458; // -32768 - 65535
int256 myInt256 = 47452848525; // int goes from 8 to 256 taking steps of 8
// address - Holds a 20 byte value (size of an Ethereum address).
// address refers to a smart contract address
// address payable refers to a wallet address which can recieve or send funds
address myAddress; //Defaults to 0x0000000000000000000000000000000000000000
address public smartAddress = address(0x7EF2e0048f5bAeDe046f6BF797943daF4ED8CB47);
address payable walletAddress = payable(0xBF4979305B43B0eB5Bb6a5C67ffB89408803d3e1);
}
Top comments (1)
Thank you for sharing this!