๊ฐ์์๋ฃ : https://ethereum-blockchain-developer.com/010-solidity-basics/01-integers/
(Unsigned) Integers
- ๋ชจ๋ ๋ณ์ ์ ํ๊ณผ ์๊ด์์ด ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ด๊ธฐํ
- ์ค๋ฅ๋ ์ ์๋์ง ์์ ๊ฐ์ด๋ null๊ฐ ์ป์ ์ ์์
- uint = uint256
- setMyuint ์์ ์ค์ ํ ๊ฐ myUint์ ๋ฐ์ / ex.5
Boolean
- Boolean ๊ฐ์ผ๋ก ์ค๋งํธ ์ปจํธ๋ํธ ์ฐ์ฅ
- Boolean : true or false ๋๊ฐ์ง ๊ฐ๋ง ๊ฐ์ง
- ์ฌ๊ณ์ฝ
- ๊ธฐ๋ณธ๊ฐ : false
- setMyBool : true ์ ๋ ฅ -> myBool : true๋ก ๊ฐ ๋ณํ
Overflow and Underflow , ์ ์ ์ํ
- uint8 : 0~255
- ๊ณ์ฝ ๋ฐฐํฌ(deploy)
- incrementUint : uint8๊ฐ 1์ฉ ์ฆ๊ฐ
- decrementUint : uint8๊ฐ 1์ฉ ๊ฐ์
- 0 ์์ decrementUint ํด๋ฆญ : uint8 ๊ฐ 255
=> ์ ์๋ ์ํํจ, ๋ฐ๋ก ์ค๋ฅ ์๋จ
Address Types
[ ์ฃผ์ ๊ณ์ ์ ์ ์ฅ ]
- myAddress : ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ฃผ์๋ 0, ๊ฐ์ผ๋ก 20byte ๋ค์ด์์
- setAddress์ ์์์ ์ ํํ ๊ณ์ (account) ๋ณต์ฌ ํ ๋ถ์ฌ๋ฃ๊ธฐ
-> transact -> myAddress ๋๋ฅด๋ฉด ์ฃผ์๊ฐ ๋ชฉ๋ก์ ๋์์๋ ๊ณ์ ์ ์ ์ฅ๋จ
Unit | Wei Value | Wei |
wei | 1wei | 1 |
Kwei (babbage) | 1e3 wei | 1,000 |
Mwei (lovelace) | 1e6 wei | 1,000,000 |
Gwei (shannon) | 1e9 wei | 1,000,000,000 |
microether (szabo) | 1e15 wei | 1,000,000,000,000 |
milliether (finney) | 1e15 wei | 1,000,000,000,000,000 |
ether | 1e18 wei | 1,000,000,000,000,000,000 |
- ์๋ฆฌ๋ํฐ์์ ์ผ์ด๋๋ ๋ชจ๋ ์ผ์ ๋ํ ๋จ์ : wei
address public myAddress;
function setAddress(address _address) public {
myAddress = _address;
}
function getBalanceOfAddress() public view returns(uint){
return myAddress.balance;
}
- ์ ํ์ด address ์ธ ๋ชจ๋ ๋ณ์๋ ๋ฉค๋ฒ๊ฐ ์ ์ด๋ ํ๋ ์์ด์ผํจ
- balance : ๋ชจ๋ ์ ๋ณด๊ฐ ๊ณต๊ฐ์ ์ผ๋ก ๋ธ๋ก์ฒด์ธ์ ์ ์ฅ๋์ด ์์ด์
์ธ์ ๋ ์ฃผ์์ ์ผ๋ง๋ ๋ง์ ์๊ธ์ด ์ ์ฅ๋์ด ์๋์ง ํ์ธ ๊ฐ๋ฅ
# ๋ค๋ฅธ ๋ฉค๋ฒ ํจ์
- ์ค๋งํธ ์ปจํธ๋ํธ์์ ํน์ ์๋์ wei๋ฅผ ์ฃผ์๋ก ์ ์ก ํ ์ ์์ : ๊ณ์ฝ์ ์ด๋ ๋ณด๋ด๊ณ ๊ฐ์ ธ์ค๊ธฐ ๊ฐ๋ฅ
[ ์ฃผ์ ์์ก ์์๋ณด๊ธฐ ]
- getBalanceOfAddress : ๋จ์ wei
- ์ฃผ์ ๋ณต์ฌํด์ setAddress์ ๋ถ์ฌ๋ฃ์ผ๋ฉด ๊ณ์ ์ ์ ์ฅ๋์ด ์๋ ์จ์ด์ ์์ผ๋ก ๊ฐ์ด ์ถ๋ ฅ๋จ
- getBalanceOfAddress => ๊ณ์ ์ ์๋ ๊ฐ๊ณผ ๋๊ฐ์
Strings
- ๋ฐ์ดํธ ๋ฐฐ์ด
-
[ ์ค๋ฅ ]
string public myString = 'hello world';
function setMyString(string _myString) public {
}
- ๋ฐ์ดํฐ ์ ์ฅ๋ ์์น๋ฅผ ํ์ ํ ์ ์๋ค๋ ์ค๋ฅ๊ฐ ๋ธ -> string ์ธ์๊ฐ ๋ฐ์ดํฐ ์์น ์ ํํ ์ง์ ํด์ผํจ
- ๋ฌธ์์ด์ด๋ ๋ค๋ฅธ ์ฐธ์กฐ์ ํ ์์ผ๋ฉด {memory} ํค์๋ ์ ๋ ฅํด์ผํจ
-> ์๋ฆฌ๋ํฐ์๊ฒ ์ด ์ธ์๋ ์คํ ๋ฆฌ์ง ๋ณ์๊ฐ ์๋๋ผ ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅ๋ ๊ฑฐ๋ผ๋ ๊ฑฐ ์๋ ค์ค (ํจ์ฌ ์)
- string public; ๋ฐฐํฌ -> ๋น ๋ฌธ์์ด ์ถ๋ ฅ
- ๋ฌธ์์ด์ ๋ด๋ถ์ ์ผ๋ก ๋ฐ์ดํธ ๋ฐฐ์ด๋ก ์ ์ฅ๋จ
- ์๋ฆฌ๋ํฐ์์ ๋ฌธ์์ด๋ก ์์ : ๊ฝค ๋น์ฉ์ด ๋ค์ด๊ฐ (๊ฐ์ค ๋๋ฌธ) , ์ค์ ๋ธ๋ก์ฒด์ธ์ผ๋ก ์์ ํ๋ ค๋ฉด ์ด๋๊ฐ ๋ง์ด ๋ค์ด๊ฐ
[ ๋ฌธ์์ด ๋ค๋ฃจ๋ ๋ฐฉ๋ฒ] ๋ค์๊ฐ์
- ์๋ฆฌ๋ํฐ ์ธ๋ถ์ ์ด๋ฒคํธ, ๋ธ๋ก์ฒด์ธ ์์ฒด์ ์ธ๋ถ์ ์ ์ฅ, ๋ธ๋ก์ฒด์ธ์ ๋ฌธ์์ด๋ง ์ ์ฅํด์ ์ธ๋ถ์ ๋ฌธ์์ด์ด ๋ง๋์ง ํ์ธ
27. ๋ฉ ๋ณ์ - ์๋ฆฌ๋ํฐ ๋ด ๋ฌธ์์ด ๊น์ง ํ์ต
[ ์๋ฆฌ๋ํฐ ์ ์ฒด ์ฝ๋ ]
pragma solidity ^0.5.13;
contract WorkingWithVariables {
uint256 public myUint;
function setMyUint(uint _myUint) public {
myUint = _myUint;
}
bool public myBool;
function setMyBool(bool _myBool) public {
myBool = _myBool;
}
uint8 public myUint8;
function incrementUint() public {
myUint8++;
}
function decrementUint() public {
myUint8--;
}
address public myAddress;
function setAddress(address _address) public {
myAddress = _address;
}
function getBalanceOfAddress() public view returns(uint){
return myAddress.balance;
}
string public myString = 'hello world';
function setMyString(string memory _myString) public {
myString = _myString;
}
}