๐ŸŒˆAddress Balance + bytesํ˜• ๋ณ€ํ™˜

RoRAยท2023๋…„ 5์›” 15์ผ
0

Solidity (use_ Remix)

๋ชฉ๋ก ๋ณด๊ธฐ
8/10

๐Ÿช‚ 2023. 05. 08. Monday_ ์—Ž๋“œ๋ ค๋ป—์ณ ๐Ÿช‚


โœ… Intro

โ€‹

์•ˆ๋…•ํ•˜์„ธ์š”!๐Ÿ˜

๋ชจ๋‘ ํ•จ๊ป˜ 4๊ฐœ์›” ๋™์•ˆ ํ•˜๋‚˜์˜ ๋ฉ‹์ง„ ํ”„๋กœ์ ํŠธ๋ฅผ ์™„์„ฑํ•˜๋Š” ๊ทธ๋‚ ๊นŒ์ง€ ํ™”์ดํŒ…ํ•ฉ์‹œ๋‹ค !๐Ÿ‘๐Ÿ‘๐Ÿ‘
โ€‹
* ์ด ๊ณณ์—์„œ๋Š” ๋‹น์ผ์— ๋ฐฐ์šด ๋‚ด์šฉ์„ ๋ณต์Šตํ•˜๋Š” ์šฉ๋„๋กœ ๊ธ€์„ ์ž‘์„ฑํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
โ€‹
* ์˜ค๋Š˜์€ Address ' Balance ๊ฐ’ ์ถ”์ถœํ•˜๊ธฐ + bytes ํ˜• ๋ณ€ํ™˜' ๋‚ด์šฉ์„ ์ •๋ฆฌํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

์—…๋กœ๋“œ์ค‘..


โ€‹
โ€‹

โœ… Address Balance

๐Ÿ‘‰ Address Balance ์‹ค์Šต์ฝ”๋“œ -(2)

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.18;

contract Address_Balance {

		//๋‚ด ์ง€๊ฐ‘ ์ž”์•ก์„ ๋ฐ˜ํ™˜์‹œ์ผœ์ฃผ๋Š” ํ•จ์ˆ˜
		function getMyBalance() public view returns(uint) {
        	return address(msg.sender).balance;
    	}
        
        //์ปจํŠธ๋ ‰ํŠธ balance๋ฅผ ๋ฐ˜ํ™˜์‹œ์ผœ์ฃผ๋Š” ํ•จ์ˆ˜
		function getContractBalance() public view returns(uint) {
        	return address(this).balance;
		}
        
}        
      

โ€‹

๐Ÿ‘‰ ์œ„ ์ฝ”๋“œ ์ •๋ฆฌํ•˜๊ธฐ !

โ€‹
โœ”๏ธ getMyBalance()

โ €โ €โ–ช๏ธ ์œ„ ํ•จ์ˆ˜๋Š” ๋‚˜์˜ ์ž”๊ณ ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ํ•จ์ˆ˜์ด๋‹ค !

โ €โ €โ–ช๏ธ msg.sender : ๊ฑฐ๋ž˜๋ฅผ ์ผ์œผํ‚จ ์‚ฌ๋žŒ == ๋ˆ„๊ฐ€ ์ด ํ•จ์ˆ˜๋ฅผ ๊ฑด๋“ค์˜€๋ƒ !!!
โ €โ €โ–ช๏ธ Balance return ๊ฐ’ : uintํ˜• (์ˆซ์žํ˜•)
โ €โ €โ–ช๏ธ address(msg.sender).balance

โ €โ €โ–ช๏ธ ์‹ค์ œ deploy ๊ฐ’๊ณผ ์•ฝ๊ฐ„์˜ ์ฐจ์ด๊ฐ€ ์žˆ์Œ~~๋‚˜์ค‘์— ๋ฐฐ์šธ ์˜ˆ์ •

โ€‹

โœ”๏ธ getContractBalance()

โ €โ €โ–ช๏ธ ์œ„ ํ•จ์ˆ˜๋Š” ์ปจํŠธ๋ ‰ํŠธ์˜ balance ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ด์ฃผ๋Š” ํ•จ์ˆ˜์ด๋‹ค.
โ €โ €โ–ช๏ธ Balance return ๊ฐ’ : uintํ˜• (์ˆซ์žํ˜•)
โ €โ €โ–ช๏ธ address(this).balance


โ€‹
โ€‹
โ€‹

โœ… Address - Bytesํ˜• ๋ณ€ํ™˜

๐Ÿ‘‰ Address-Bytes ์‹ค์Šต์ฝ”๋“œ -(3)

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.18;

contract Address_Bytes {

		address a;
		
		function setA(address _a) public {
			a = _a;
		}


		function setA2(bytes20 _a) public {
			a = address(_a);
		}
        
        
        //์˜ค๋ฅ˜ 1
		//function setA2(bytes20 _a) public {
		//    a = _a;
		//}

		function getA() public view returns(address) {
			return a;
		}
		function getA2() public view returns(bytes20){
			return bytes20(a);
		}
        
        
        //์˜ค๋ฅ˜ 2
		//function getA2() public view returns(bytes20){
		//	return a;
		//}

}

โ€‹
โ€‹

๐Ÿ‘‰ ์œ„ ์ฝ”๋“œ ์ •๋ฆฌํ•˜๊ธฐ !

โ€‹
โœ”๏ธ ํ•ต์‹ฌ !

โ €โ €โ–ช๏ธ addressํ˜•: 20๋ฐ”์ด์ธ 
โ €โ €โ–ช๏ธ bytesํ˜•: 20๋ฐ”์ด์ธ 

โ €โ €โ € โ €โ €๐Ÿ”ธ๋‘˜์˜ ๊ธธ์ด๋Š” ๋‹ค๋ฅด์ง€๋งŒ, ํ˜•์ด ๋‹ค๋ฅด๋ฏ€๋กœ ๊ฐ’์ด ๊ฐ™์„ ์ˆ˜๋Š” ์—†๋‹ค.
โ €โ €โ € โ €โ €๐Ÿ”ธ= ๊ธธ์ด๋งŒ ๊ฐ™๊ณ  ํ˜•์ด ๋‹ค๋ฅด๋‹ค~!~!~!
โ€‹

โœ”๏ธ ๊ธธ์ด๋งŒ ๊ฐ™์€ ์ƒํ™ฉ์ด๋ผ๋ฉด, ํ˜•๊นŒ์ง€ ๋งž์ถฐ์ฃผ์ž ~!!!


โ€‹

โ €โ €โ €

๐Ÿ“Œ23. 05. 08

ใ…‹ใ…‹ใ…‹ใ…‹๋ชจ๋ฅด๊ฒ ์œผ๋ฉด? ๋ƒ…๋‹ค ํ•ด~

0๊ฐœ์˜ ๋Œ“๊ธ€