๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

web3 ๊ณต๋ถ€ (24.7. 15 ~ )/3์ฃผ์ฐจ

3์ฃผ์ฐจ - ์†”๋ฆฌ๋””ํ‹ฐ Event, modifier, receive,fallback,call,delegate call (๋ฏธ์™„)

๐Ÿ’ก์†”๋ฆฌ๋””ํ‹ฐ์—์„œ Event

์ด๋ฒคํŠธ๋Š” ๋ธ”๋ก์ฒด์ธ ๋กœ๊ทธ๋ฅผ ๊ธฐ๋กํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

๋ธ”๋ก์ฒด์ธ์— ๋กœ๊ทธ๋กœ ์ €์žฅ๋˜๋ฉฐ, ์™ธ๋ถ€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์ด ๋กœ๊ทธ๋ฅผ ๊ฐ์ง€ํ•˜์—ฌ ํŠน์ • ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, ํ† ํฐ ์ „์†ก์ด ๋ฐœ์ƒํ•  ๋•Œ๋งˆ๋‹ค ์ด๋ฒคํŠธ๋ฅผ ๋ฐœ์ƒ์‹œ์ผœ ์™ธ๋ถ€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์ด๋ฅผ ๊ฐ์ง€ํ•˜๊ณ  ์‚ฌ์šฉ์ž์—๊ฒŒ ์•Œ๋ฆผ์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๐Ÿ’กreceive์™€ fallback

์ด๋”๋ฅผ ์ˆ˜์‹ ํ•  ๋•Œ ํ˜ธ์ถœ๋˜๋Š” ํŠน๋ณ„ํ•œ ํ•จ์ˆ˜๋“ค์ž…๋‹ˆ๋‹ค.

  • receive: ๊ธฐ๋ณธ ์ด๋” ์ˆ˜์‹  ํ•จ์ˆ˜, ๋‹จ์ˆœํ•œ ์ด๋” ์ˆ˜์‹ ์„ ์ฒ˜๋ฆฌํ•จ.
  • fallback: ํ˜ธ์ถœ๋œ ํ•จ์ˆ˜๊ฐ€ ์—†์„ ๋•Œ ์‹คํ–‰, ์ด๋” ์ˆ˜์‹  ๋ฐ ํ•จ์ˆ˜ ํ˜ธ์ถœ ์‹คํŒจ ์‹œ ์ž‘๋™ํ•œ๋‹ค.

 

๐Ÿ’กcall์™€ delegate call

  • call: ๋‹ค๋ฅธ ์ปจํŠธ๋ž™ํŠธ์˜ ํ•จ์ˆ˜ ํ˜ธ์ถœ
(bool success, ) = otherContract.call{value: msg.value}("");
require(success, "Call failed");
  • delegatecall: ํ˜ธ์ถœ๋œ ์ปจํŠธ๋ž™ํŠธ์˜ ์ปจํ…์ŠคํŠธ๋ฅผ ํ˜ธ์ถœ์ž ์ปจํŠธ๋ž™ํŠธ์— ์ ์šฉ
(bool success, ) = otherContract.delegatecall(abi.encodeWithSignature("someFunction()"));
require(success, "Delegatecall failed");