[ Solidity νμ΅ μμ ]
-
ν¬λ¦½ν μ’λΉ
https://cryptozombies.io/ko/course -
μΈνλ°
https://www.inflearn.com/course/blockchain-%EC%9D%B4%EB%8D%94%EB%A6%AC%EC%9B%80-dapp#curriculum -
dapp university
https://www.youtube.com/watch?v=CgXQC4dbGUE&t=783s
[Warm-up reference]
λΈλ‘체μΈμ΄λ(μ리, νμ©, μ λ§)
http://wiki.hash.kr/index.php/%EB%B8%94%EB%A1%9D%EC%B2%B4%EC%9D%B8#.EC.9E.91.EB.8F.99_.EC.9B.90.EB.A6.AC
λΈλ‘μ²΄μΈ κ΅¬μ‘° μ€λͺ
https://brownbears.tistory.com/371?category=281929
μμ
μ¦λͺ
https://brownbears.tistory.com/373?category=281929
μ§λΆμ¦λͺ
http://wiki.hash.kr/index.php/%EC%A7%80%EB%B6%84%EC%A6%9D%EB%AA%85#cite_note-2
https://www.youtube.com/watch?v=psKDXvXdr7k&t=64s
μ°λ‘보λ‘μ€ μ§λΆμ¦λͺ
http://wiki.hash.kr/index.php/%EC%9A%B0%EB%A1%9C%EB%B3%B4%EB%A1%9C%EC%8A%A4_%EC%A7%80%EB%B6%84%EC%A6%9D%EB%AA%85
nonce μ€λͺ
http://wiki.hash.kr/index.php/%EB%85%BC%EC%8A%A4_(%EC%9E%84%EC%8B%9C%EA%B0%92)
λΈλ‘체μΈμ λ€μμ κ±°λλ΄μμ λͺ¨μ νλμ λΈλ‘μ ꡬμ±νκ³ , κ·Έ λΈλ‘μ λννλ ν΄μκ°μ μμ±νμ¬ λ€λ₯Έ λΈλ‘κ³Ό 체μΈμ²λΌ μ°κ²°λλ€. μ΄ λ, λΈλ‘μ λννλ ν΄μκ°μΈ λΈλ‘ν΄μλ₯Ό μμ±νλ €λ©΄, μΌμ ν 쑰건μ λ§μ‘±ν΄μΌ νλ€. κ·Έ μΌμ ν 쑰건μ΄λ, λΈλ‘ λμ΄λμ λ°λΌ μλμΌλ‘ μ€μ λ 'λͺ©νκ°'λ³΄λ€ λ μμ λΈλ‘ν΄μκ°μ μ°ΎμμΌ νλ€λ μ μ½μ‘°κ±΄μ΄λ€. ν΄μλ λλ€νκ² μμ±λκΈ° λλ¬Έμ, μμμ΄ λ§μ μ°μ°μ λ°λ³΅ν΄μ 미리 μ ν΄μ§ λͺ©νκ° μ΄νμ ν΄μκ°μ΄ λμ€λλ‘ ν΄μΌ νλ€. μ΄λ λλ€ν ν΄μκ°μ μμ±ν μ μλλ‘ λ§€λ² μμκ°μ μ¬μ©ν΄μΌ νλλ°, κ·Έ μμκ°μ΄ λ°λ‘ λ Όμ€μ΄λ€.
μΌλ°μ μΌλ‘ λΈλ‘μ ν΄μκ°μ ν΄λΉ λΈλ‘μ μμ±μΌμ, λ²μ , λΉμΈ (bits), 루νΈν΄μ, μ΄μ λΈλ‘μ ν΄μ, κ·Έλ¦¬κ³ λ Όμ€(nonce)λΌκ³ λΆλ¦¬λ μμκ° λ±μ μ‘°ν©ν ν ν΄μλ‘ λ³ννμ¬ μμ±νλ€. ν΄λΉ λΈλ‘μ μμ±μΌμ, λ²μ , λμ΄λ, 루νΈν΄μμ μ΄μ λΈλ‘μ ν΄μκ°μ μ΄λ―Έ νμ λμ΄ μ ν΄μ§ κ°μ κ°μ§κ³ μμ§λ§, λ Όμ€λΌλ μμκ°μ΄ λ¬λΌμ§μ λ°λΌ ν΄μ μ°μ° κ²°κ³Όλ‘ μμ±λλ λΈλ‘ ν΄μκ°λ λ€μνκ² λμ¬ μ μλ€. μλ₯Ό λ€μ΄ λ Όμ€κ° 1μΈ κ²½μ°μ ν΄μκ°κ³Ό 2μΈ κ²½μ°μ ν΄μκ°μ μ ν λ€λ₯΄λ€. μ΄ λ Όμ€ κ°μ μμμ΄ λ°κΏκ°λ©΄μ νλμ© λμ νλ€κ° μλ‘ μμ±λ ν΄μκ°μ΄ μΌμ ν λͺ©νκ°λ³΄λ€ λ μμ κ²½μ°μ μλ‘μ΄ λΈλ‘μ΄ μ±κ³΅μ μΌλ‘ μμ±λλ€.
λ¨Έν΄λ£¨νΈ
http://wiki.hash.kr/index.php/%EB%A8%B8%ED%81%B4%EB%A3%A8%ED%8A%B8
bits μ€λͺ
(+λΈλ‘μ²΄μΈ μλ λ°©μ μ€λͺ
)
https://homoefficio.github.io/2016/01/23/BlockChain-%EA%B8%B0%EC%B4%88-%EA%B0%9C%EB%85%90/
μ€λ§νΈ 컨νΈλνΈλ?
https://medium.com/haechi-audit-kr/smart-contract-a-to-z-79ebc04d6c86
web3.jsλ?
http://wiki.hash.kr/index.php/Web3.js
nftλ? https://v.kakao.com/v/20210401051201642
μ½μΈκ³Ό ν ν°μ μ°¨μ΄ https://www.tokenpost.kr/terms/11550
μ½μΈ λ©μΈλ·μ΄λ? https://webruden.tistory.com/530
geth ν°λ―Έλ λͺ
λ Ήμ΄
https://geth.ethereum.org/docs/interface/command-line-options
[μ리λν° κ΄λ ¨ μλ£ λͺ¨μ]
- λ¬Έλ²
μ½λ© μ€νμΌκ°μ΄λ
https://solidity-kr.readthedocs.io/ko/latest/style-guide.html#index-0
λͺ
λͺ
κ·μΉ
https://solidity-kr.readthedocs.io/ko/latest/style-guide.html#id16
μ리λν° μ½λ λ μ΄μμ(μ€νμΌκ°μ΄λ)
https://docs.soliditylang.org/en/v0.5.2/style-guide.html#code-layout
https://medium.com/returnvalues/%EC%86%94%EB%A6%AC%EB%94%94%ED%8B%B0-v-0-5-2-%EC%8A%A4%ED%83%80%EC%9D%BC-%EA%B0%80%EC%9D%B4%EB%93%9C-19e2686201f6
μ¬κΈ°λ λ¬Έλ²κ°λ
μ λΆλ₯ν΄μ μμν¨μλ€λ‘ μ€λͺ
ν¨. visibility, ν¨μ μ μ΄μ, λ°μ΄ν° μ ν.
https://potensj.tistory.com/18?category=671470
μ κ·Ό μ μ΄μ(Visibility)μ λν΄μλ§ λ€λ£¬ κΈ
https://caileb.tistory.com/140
μν μ μ΄μ μ€λͺ
μν΄λμ κΈ
https://codemath.github.io/Solidity-%EC%9D%B4%EB%8D%94%EB%A6%AC%EC%9B%80-%EA%B8%B0%EB%B0%98-Dapp-%EA%B0%9C%EB%B0%9C%EA%B8%B0(2)-Solidity-%EC%96%B8%EC%96%B4-%EC%A0%95%EB%A6%AC/
μ¬κΈ΄ μ€λ§νΈ 컨νΈλνΈ κ΅¬μ‘°, λ³μ, λ°μ΄ν° μμΉ λ± μ λ°μ μΌλ‘ λ€λ£¬λ€.
https://d2fault.github.io/2018/03/19/20180319-about-solidity-1/
import
https://solidity-kr.readthedocs.io/ko/latest/layout-of-source-files.html#index-3
storageμ memory
https://www.geeksforgeeks.org/storage-vs-memory-in-solidity/
https://docs.soliditylang.org/en/v0.5.3/types.html
- κ°λ
modifier
https://intrepidgeeks.com/tutorial/understanding-the-basics-of-entities-2
msgλ?
msg (tx μ block ν¬ν¨)λ μ μ©ν μ μ λ³μλ‘ λΈλ‘체μΈμ μ κ·Όν μ μλ λ€μν μμ±λ€μ λ΄κ³ μμ΅λλ€.
msg.sender λ μΈλΆμμ μ§κΈ ν¨μλ₯Ό νΈμΆν μ£Όμλ₯Ό λνλ
λλ€.
https://solidity-kr.readthedocs.io/ko/latest/introduction-to-smart-contracts.html?highlight=msg#subcurrency μμ 'μ μ©ν μ μ λ³μ' κ²μ.
msg λ©€λ² κ°.
https://solidity-kr.readthedocs.io/ko/latest/units-and-global-variables.html#index-2
bytes(λμ ν¬κΈ° λ°μ΄νΈ λ°°μ΄)
https://solidity-kr.readthedocs.io/ko/latest/types.html#id7
μλ£ν (κ°μ² μ λΈλ‘μ²΄μΈ μ νλΈ μ±λ μ΄μμμ λΈλ‘κ·Έ)
https://needjarvis.tistory.com/255
SHA-3 λ?
https://ko.wikipedia.org/wiki/SHA-3
keccak-256μ΄λ?
http://wiki.hash.kr/index.php/Keccak-256
abiλ?
https://hucet.tistory.com/46
https://cryptozombies.io/ko/lesson/6/chapter/3
μ΄λ리μκ³Ό abi κ΄λ ¨. apiμ λΉκ΅.
https://medium.com/pocs/ethereum-abi%EC%99%80-%EA%B4%80%EB%A0%A8%EB%90%9C-q-a-%EC%A0%95%EB%A6%AC-40e639ee1a03
abi-encodepackedλ?
https://frontalnh.github.io/categories/ethereum/blockchain/
μ리λν°μμμ eventμ λνμ¬ (dApp = μ€λ§νΈ 컨νΈλνΈ + νλ‘ νΈμλ)
μ리λν° μμλ print κΈ°λ₯μ΄ λ°λ‘ μλ€. λμ eventλ‘ νΉμ κ°μ λΈλ‘μ μ μ₯νμ¬ emitμΌλ‘ μΆλ ₯ν μ μλ€.
https://nujabes403.medium.com/solidity-event%EC%97%90-%EB%8C%80%ED%95%B4%EC%84%9C-6ed040e12808
https://www.youtube.com/watch?v=fbkt4u4yRzk
https://www.youtube.com/watch?v=P39o5c3J7IA
λ§€νκ³Ό ꡬ쑰체μ μ°¨μ΄
https://m.blog.naver.com/PostView.nhn?blogId=blokorea&logNo=221311000461&proxyReferer=https:%2F%2Fwww.google.com%2F
ꡬ쑰체 λ°°μ΄ μ¬μ©μμ
https://hatpub.tistory.com/56
virtual
Solidityμμ 'virtual' ν€μλλ μμ κ΄κ³μ μλ 컨νΈλνΈ κ°μ ν¨μλ₯Ό μ€λ²λΌμ΄λ©(μ¬μ μ)νλ λͺ©μ μΌλ‘ μ¬μ©λ©λλ€. 'virtual' ν€μλλ₯Ό μ¬μ©νμ¬ ν¨μλ₯Ό μ μΈνλ©΄ ν΄λΉ ν¨μλ νμ ν΄λμ€μμ μ¬μ μλ μ μμ΅λλ€. 'virtual' ν€μλλ₯Ό μ¬μ©νμ¬ μ μΈλ ν¨μλ κΈ°λ³Έ ꡬνμ κ°μ§λ©°, νμ ν΄λμ€μμ νμμ λ°λΌ ν΄λΉ ν¨μλ₯Ό μ¬μ μν μ μμ΅λλ€. μ΄λ Solidityμμμ λ€νμ±κ³Ό μ μ°μ±μ μ 곡ν©λλ€. λ€μμ 'virtual' ν€μλλ₯Ό μ¬μ©νμ¬ ν¨μλ₯Ό μ μΈνλ μμμ λλ€:
contract Base {
function foo() public virtual returns (uint) {
// κΈ°λ³Έ ꡬν
return 42;
}
}
contract Derived is Base {
function foo() public virtual override returns (uint) {
// κΈ°λ³Έ ꡬνμ μ¬μ μ
return 10;
}
}μμ μμμμ Base 컨νΈλνΈμ foo ν¨μλ virtualλ‘ μ μΈλμμ΅λλ€. Derived 컨νΈλνΈλ Base 컨νΈλνΈλ₯Ό μμλ°κ³ , foo ν¨μλ₯Ό override ν€μλλ₯Ό μ¬μ©νμ¬ μ¬μ μνμμ΅λλ€. μ΄μ Derived 컨νΈλνΈμ μΈμ€ν΄μ€μμ foo ν¨μλ₯Ό νΈμΆνλ©΄ Derived 컨νΈλνΈμμ μ¬μ μλ ꡬνμ΄ μ€νλ©λλ€.
Derived instance = new Derived();
uint result = instance.foo(); // 10μ λ°νμ΄μ κ°μ΄ 'virtual' ν€μλλ₯Ό μ¬μ©νμ¬ μ μΈλ ν¨μλ μμ κ΄κ³μμ μ€λ²λΌμ΄λ©λ μ μμΌλ©°, νμ ν΄λμ€μμ ν΄λΉ ν¨μμ λμμ μ¬μ μν μ μμ΅λλ€. μ΄λ Solidityμμ λ€νμ±κ³Ό μμμ νμ©νμ¬ μ μ°νκ³ λͺ¨λνλ μ€λ§νΈ 컨νΈλνΈλ₯Ό ꡬννλ λ° λμμ μ€λλ€.
μ€λ²λΌμ΄λ(override)
Solidityμ 'override' ν€μλλ μμ κ΄κ³μ μλ 컨νΈλνΈμμ ν¨μλ₯Ό μ€λ²λΌμ΄λ©(μ¬μ μ)ν λ μ¬μ©λ©λλ€. 'override' ν€μλλ₯Ό μ¬μ©νμ¬ ν¨μλ₯Ό μ μΈνλ©΄ μ»΄νμΌλ¬κ° ν΄λΉ ν¨μκ° μμ ν΄λμ€μ ν¨μλ₯Ό μ¬μ μνκ³ μλμ§ νμΈν©λλ€.
'override' ν€μλλ₯Ό μ¬μ©νμ¬ ν¨μλ₯Ό μ μΈνλ©΄ λ€μκ³Ό κ°μ 쑰건μ μΆ©μ‘±ν΄μΌ ν©λλ€
- μμ κ΄κ³μμ ν΄λΉ ν¨μλ₯Ό μ¬μ μν λ 'override' ν€μλλ₯Ό μ¬μ©ν΄μΌ ν©λλ€.
- ν¨μ μ΄λ¦, λ§€κ°λ³μμ κ°μμ νμ λ° μμ, λ°νκ°μ νμ μ΄ λμΌν΄μΌ ν¨
contract Base {
function foo(uint a) public virtual returns (uint) {
// κΈ°λ³Έ ꡬν
return a * 2;
}
}
contract Derived is Base {
function foo(uint a) public override returns (uint) {
// μμ ν΄λμ€μ ν¨μλ₯Ό μ¬μ μ
// μΆκ°μ μΈ λμ μν
return a + 10;
}
}
// μλͺ»λ μμ(bλΌλ λ€λ₯Έ λ§€κ°λ³μ μ΄λ¦μ μ¬μ©νκ³ , λ°νκ° νμ
μ numberλ‘ λ³κ²½νμ΅λλ€. μ΄λ μ¬λ°λ₯Έ μ€λ²λΌμ΄λ©μ΄ μλκΈ° λλ¬Έμ μ»΄νμΌλ¬κ° μ€λ₯λ₯Ό λ°μμν΅λλ€)
contract Derived is Base {
function foo(uint b) public override returns (number) {
// μμ ν΄λμ€μ ν¨μλ₯Ό μ¬μ μ
// μΆκ°μ μΈ λμ μν
return b + 10;
}
}μμ±μ(constructor)
https://caileb.tistory.com/137
https://docs.soliditylang.org/en/v0.7.5/contracts.html?highlight=constructor#constructors
μμ±μμ κ°μμ±μ λν μ΄μ μ
λ°μ΄νΈ - Visibility (public / external) is not needed for constructors anymore:
https://docs.soliditylang.org/en/v0.7.0/070-breaking-changes.html#functions-and-events
κ°μ€λ?
https://phemex.com/ko/academy/%EC%9D%B4%EB%8D%94%EB%A6%AC%EC%9B%80-%EA%B0%80%EC%8A%A4%EB%9E%80
payable μ μ΄μ
https://www.crocus.co.kr/1254
address κ΄λ ¨ (balance, transfer λ±)
https://solidity-kr.readthedocs.io/ko/latest/types.html?highlight=balance#address-members
https://solidity-kr.readthedocs.io/ko/latest/units-and-global-variables.html
μ΄λ리μ κ³μ (Account), νΈλμμ
(Transaction), λ©μμ§(Message) + μ€λ§νΈ 컨νΈλνΈ
https://brownbears.tistory.com/385
μμ ν λμμμ±
https://ethereum.stackexchange.com/questions/191/how-can-i-securely-generate-a-random-number-in-my-smart-contract
ERC-20(λ체 κ°λ₯)
http://wiki.hash.kr/index.php/ERC-20
μ¬μ©κ·μΉ : http://wiki.hash.kr/index.php/ERC-20#.EA.B7.9C.EC.B9.99
ERC-721(λ체 λΆκ°λ₯)
http://wiki.hash.kr/index.php/ERC-721#OpenZeppelin
ERC-721 νμ€μ
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md#specification
ERC μ 리
https://eips.ethereum.org/erc
μΆμ 컨νΈλνΈ(abstract contract), μΈν°νμ΄μ€.
https://goodgid.github.io/Ethereum-Basic-Solidity-(8)/
https://medium.com/upstate-interactive/solidity-how-to-know-when-to-use-abstract-contracts-vs-interfaces-874cab860c56
μΈν°νμ΄μ€
https://www.youtube.com/watch?v=7H9eb_6QRAk
*μΈν°νμ΄μ€λ₯Ό μ¬μ©νλ μν©μμ, μΈν°νμ΄μ€ λ΄ ν¨μλ₯Ό μ¬μ©(μ μ)ν λλ override ν€μλλ₯Ό λͺ
μν΄μΌ νλ€.
https://cryptozombies.io/ko/lesson/2/chapter/10
μ€λ²λΌμ΄λ©
https://docs.soliditylang.org/en/v0.6.0/contracts.html#function-overriding
- ν¨μ overriding μ, λ€μ€ μμ(νΉμ μ°μ μμ)μ΄ μΌμ΄λ κ²½μ° overriding νλ €λ ν¨μμ contractλ₯Ό λͺ
μν΄μ€μΌ νλ€.
http://wiki.hash.kr/index.php/%EC%98%A4%EB%B2%84%EB%9D%BC%EC%9D%B4%EB%94%A9
https://medium.com/upstate-interactive/solidity-override-vs-virtual-functions-c0a5dfb83aaf
μ€λ²λ‘λ©
http://wiki.hash.kr/index.php/%EC%98%A4%EB%B2%84%EB%A1%9C%EB%94%A9
https://solidity-kr.readthedocs.io/ko/latest/contracts.html#index-11
λ°μ΄ν° λ¨μ(λΉνΈ, λ°μ΄νΈ..) 8bit == 2^8 - 1 == (2^7) + (2^6) + ... + (2^0)
https://kbench.com/?q=node/2635
μ€λ²νλ‘μ° λ°μ μμ
https://steemit.com/kr-dev/@modolee/the-go-programming-language-3-3-1
μμ£Ό μ°μ΄λ ν¨ν΄
https://solidity-kr.readthedocs.io/ko/latest/common-patterns.html
λΌμ΄λΈλ¬λ¦¬(library)
https://www.youtube.com/watch?v=CkQDssQ7EJM
https://solidity-kr.readthedocs.io/ko/latest/contracts.html#libraries
super.
https://solidity-kr.readthedocs.io/ko/latest/miscellaneous.html#index-4
super ν€μλλ μ£Όλ‘ λ κ°μ§ μν©μμ μ¬μ©λ©λλ€
- ν¨μ μ€λ²λΌμ΄λ© (Function Overriding): λ§μ½ μμ 컨νΈλνΈκ° λΆλͺ¨ 컨νΈλνΈλ‘λΆν° ν¨μλ₯Ό μμλ°μ λμΌν μ΄λ¦μ ν¨μλ₯Ό μ μνκ³ μ ν λ, superλ₯Ό μ¬μ©νμ¬ λΆλͺ¨ 컨νΈλνΈμ ν¨μλ₯Ό νΈμΆν μ μμ΅λλ€. μ΄λ μμ 컨νΈλνΈμμ λΆλͺ¨ 컨νΈλνΈμ λμμ μ μ§νλ©΄μ μΆκ°μ μΈ λμμ μννκ³ μ ν λ μ μ©ν©λλ€. μλ₯Ό λ€μ΄
contract Parent {
function foo() public virtual {
// λΆλͺ¨ 컨νΈλνΈμ λμ
}
}
contract Child is Parent {
function foo() public override {
// λΆλͺ¨ 컨νΈλνΈμ λμ μ μ§νκ³ μΆκ°μ μΈ λμ μν
super.foo();
// μΆκ° λμ
}
}μμ 컨νΈλνΈμμ super.foo()λ₯Ό νΈμΆν¨μΌλ‘μ¨ λΆλͺ¨ 컨νΈλνΈμ foo() ν¨μλ₯Ό μ€νν μ μμ΅λλ€.
2. λ³μ λ° modifier μ κ·Ό
superλ₯Ό μ¬μ©νμ¬ λΆλͺ¨ 컨νΈλνΈμ λ³μμ modifierμ μ κ·Όν μ μμ΅λλ€. μμ 컨νΈλνΈμμ superλ₯Ό μ¬μ©νμ¬ λΆλͺ¨ 컨νΈλνΈμ λ³μ κ°μ κ°μ Έμ¬ μ μμΌλ©°, modifierλ₯Ό μμλ°μ κ²½μ° superλ₯Ό μ¬μ©νμ¬ λΆλͺ¨ modifierλ₯Ό μ€νν μ μμ΅λλ€.
contract Parent {
uint public x;
modifier onlyOwner {
require(msg.sender == owner);
_;
}
}
contract Child is Parent {
function setX(uint _x) public onlyOwner {
// λΆλͺ¨ 컨νΈλνΈμ λ³μμ μ κ·Ό
super.x = _x
// λΆλͺ¨ 컨νΈλνΈμ modifier μ€ν
super.onlyOwner();
// μΆκ° λμ
}
}μμ 컨νΈλνΈμμ super.xλ₯Ό ν΅ν΄ λΆλͺ¨ 컨νΈλνΈμ λ³μμ μ κ·Όνκ±°λ, super.onlyOwner()λ₯Ό νΈμΆνμ¬ λΆλͺ¨ 컨νΈλνΈμ modifierλ₯Ό μ€νν μ μμ΅λλ€.
Using For
https://solidity-kr.readthedocs.io/ko/latest/contracts.html#using-for
// example 1
library Math {
function add(uint a, uint b) internal pure returns (uint) {
return a + b;
}
}
struct Number {
uint value;
}
using Math for Number;
function addTwoNumbers(uint a, uint b) public view returns (uint) {
Number memory num = Number(a);
return num.add(b); // Math λΌμ΄λΈλ¬λ¦¬μ add ν¨μλ₯Ό νΈμΆ
}pragma solidity >=0.4.16 <0.6.0;
// example 2
// This is the same code as before, just without comments
library Set {
struct Data { mapping(uint => bool) flags; }
function insert(Data storage self, uint value)
public
returns (bool)
{
if (self.flags[value])
return false; // already there
self.flags[value] = true;
return true;
}
function remove(Data storage self, uint value)
public
returns (bool)
{
if (!self.flags[value])
return false; // not there
self.flags[value] = false;
return true;
}
function contains(Data storage self, uint value)
public
view
returns (bool)
{
return self.flags[value];
}
}
contract C {
using Set for Set.Data; // this is the crucial change
// Setμ Set.DataλΌλ νμ
μ κ°μ§ λ³μ(Set.Data knownValues;)κ° μ¬μ©ν μ μλλ‘ ν΄μ€λ€. κ·Έλμ Set.Data νμ
μ λ³μκ° λΌμ΄λΈλ¬λ¦¬ Set μμ μλ insert ν¨μλ₯Ό μ¬μ©ν μ μλ€.
Set.Data knownValues;
// Here, all variables of type Set.Data have
// corresponding member functions.
// The following function call is identical to
// `Set.insert(knownValues, value)`
function register(uint value) public {
require(knownValues.insert(value));
}
}assert : μ‘°κ±΄μ΄ μΆ©μ‘±λμ§ μμΌλ©΄ μμΈλ₯Ό λ°μμν΅λλ€ - λ΄λΆ μλ¬μ μ¬μ©λ©λλ€.
require : μ‘°κ±΄μ΄ μΆ©μ‘±λμ§ μμΌλ©΄ μμΈλ₯Ό λ°μμν΅λλ€ - μ
λ ₯ λλ μΈλΆ μμμ μλ¬μ μ¬μ©λ©λλ€.
https://solidity-kr.readthedocs.io/ko/latest/units-and-global-variables.html?highlight=assert#index-3.
assert : ν¨μ μ€νμ΄ μ€ν¨ν΄λ λ¨μ κ°μ€ λλ €μ£Όμ§ μμ.
require : ν¨μ μ€νμ΄ μ€ν¨νλ©΄ λ¨μ κ°μ€ λλλ €μ€.
https://cryptozombies.io/ko/lesson/5/chapter/10
λΈλ‘μ²΄μΈ λ€νΈμν¬, λ
Έλ
https://www.youtube.com/watch?v=u4voz9XBbWA
μΊμλ
https://ko.wikipedia.org/wiki/%EC%BA%90%EC%8B%9C
https://mangkyu.tistory.com/69
-Web3.js μ 컨νΈλνΈμ ν΅μ
νμν κ² : 컨νΈλνΈ μ£Όμ, 컨νΈλνΈ ABI
컨νΈλνΈ μ£Όμ - μ΄λ리μμ λ°°ν¬νλ©΄ μꡬμ μ΄κ³ κ³ μ λ μ£Όμλ₯Ό μ»κ² λ¨. 볡μ¬ν΄μ μ¬μ©.
컨νΈλνΈ ABI - μ΄λ리μμ μ΄λ리μμ λ°°ν¬νκΈ° μν΄ μ»¨νΈλνΈλ₯Ό μ»΄νμΌν λ, μ리λν° μ»΄νμΌλ¬κ° μλ€μκ² ABIλ₯Ό μ€.
(ν΄λΉ λ΄μ© μ±ν° : https://cryptozombies.io/ko/lesson/6/chapter/3)
λΉλκΈ° μ²λ¦¬λ°©μ
https://joshua1988.github.io/web-development/javascript/javascript-asynchronous-operation/
μλ°μ€ν¬λ¦½νΈ promise
https://joshua1988.github.io/web-development/javascript/promise-for-beginners/
μλ°μ€ν¬λ¦½νΈ setinterval
https://kyounghwan01.github.io/blog/JS/JSbasic/intervalFunction/#setinterval
μλ°μ€ν¬λ¦½νΈ es6 for of(+for in)
https://jsdev.kr/t/for-in-vs-for-of/2938
μλ°μ€ν¬λ¦½νΈ template literal
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Template_literals
.on μ΄λ²€νΈ λ°μΈλ©
http://www.devkuma.com/books/pages/232
- indexed ν€μλ
https://solidity-kr.readthedocs.io/ko/latest/miscellaneous.html#index-6
https://docs.soliditylang.org/en/latest/contracts.html#events
μ£Όμ κΈ°λ₯
- λ‘κ·Έ νν°λ§ κ°λ₯
- indexedλ‘ νμλ λ§€κ°λ³μλ μ΄λ²€νΈ λ‘κ·Έλ₯Ό νν°λ§νλ λ° μ¬μ©ν μ μμ΅λλ€
- νΉμ μ£Όμλ κ°μΌλ‘ μ΄λ²€νΈλ₯Ό κ²μν μ μκ² ν΄μ€λλ€
- μ μ₯ λ°©μμ μ°¨μ΄ - indexed λ§€κ°λ³μ: λ‘κ·Έμ topicsμ μ μ₯ (κ²μ κ°λ₯) - μΌλ° λ§€κ°λ³μ: λ‘κ·Έμ dataμ μ μ₯ (κ²μ λΆκ°, λ¨μ λ°μ΄ν°)
- μ΅λ 3κ°κΉμ§ μ ν - νλμ μ΄λ²€νΈμμ μ΅λ 3κ°μ λ§€κ°λ³μλ§ indexedλ‘ μ§μ κ°λ₯
μ¬μ© μμ
event Transfer(address indexed from, address indexed to, uint256 value);
μ΄λ κ² μ μνλ©΄:
- νΉμ μ£Όμ(from)κ° λ³΄λΈ λͺ¨λ Transfer μ΄λ²€νΈλ₯Ό κ²μ κ°λ₯
- νΉμ μ£Όμ(to)κ° λ°μ λͺ¨λ Transfer μ΄λ²€νΈλ₯Ό κ²μ κ°λ₯
- valueλ indexedκ° μλλ―λ‘ κ²μ κΈ°μ€μΌλ‘ μ¬μ© λΆκ° (λ¨μ λ°μ΄ν° μ μ₯)
μ μ¬μ©νλμ?
- ν¨μ¨μ μΈ λ°μ΄ν° μ‘°ν: νλ‘ νΈμλλ λ°±μλμμ νΉμ μ£Όμμ κ±°λ λ΄μλ§ νν°λ§ν΄μ κ°μ Έμ¬ μ μμ΅λλ€
- λΉμ© μ΅μ ν: λͺ¨λ μ΄λ²€νΈλ₯Ό κ°μ Έμμ νν°λ§νλ λμ , λΈλ‘μ²΄μΈ λ 벨μμ νν°λ§ κ°λ₯
- μ¬μ©μ κ²½ν: μ¬μ©μλ³ κ±°λ λ΄μ, νΉμ ν ν°μ μ΄λ μΆμ λ±μ΄ λΉ λ₯΄κ² κ°λ₯ν©λλ€
Deposit μ΄λ²€νΈ (24λ²μ§Έ μ€): event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
- senderμ ownerλ indexed β νΉμ μ¬μ©μμ μ κΈ λ΄μ κ²μ κ°λ₯
- assetsμ sharesλ μΌλ° λ§€κ°λ³μ β λ¨μ λ°μ΄ν° μ μ₯
Withdraw μ΄λ²€νΈ (34-40λ²μ§Έ μ€): event Withdraw( address indexed sender, address indexed receiver, address indexed owner, uint256 assets, uint256 shares );
- 3κ°μ μ£Όμκ° λͺ¨λ indexed (μ΅λ 3κ°)
- νΉμ μ¬μ©μκ° μΆκΈν λ΄μ, λ°μ λ΄μ λ±μ κ°κ° νν°λ§ κ°λ₯
μ€μ μ¬μ© μλ리μ€
νλ‘ νΈμλμμ μ΄λ κ² μ¬μ©ν μ μμ΅λλ€:
// νΉμ μ¬μ©μ(0x123...)κ° λ°μ λͺ¨λ Deposit μ΄λ²€νΈ μ‘°ν const deposits = await contract.queryFilter( contract.filters.Deposit(null, "0x123...") );
// νΉμ μ¬μ©μκ° λ³΄λΈ λͺ¨λ Withdraw μ΄λ²€νΈ μ‘°ν const withdrawals = await contract.queryFilter( contract.filters.Withdraw("0x123...", null, null) );
λ§μ½ indexedκ° μμλ€λ©΄, λͺ¨λ μ΄λ²€νΈλ₯Ό λ€ κ°μ Έμμ JavaScriptμμ νν°λ§ν΄μΌ νλ―λ‘ λ§€μ° λΉν¨μ¨μ μ΄μμ κ²λλ€!
- web3jsμμ λ©μλ, μ΄λ²€νΈλ₯Ό λ€λ£¨λ λ²
ex - CryptoZombies.methods.createRandomZombie(name)
ex - cryptoZombies.events.NewZombie()...
overflow, underflow
https://gjwjdgnsrnlg.tistory.com/201
** Call method
(bool λ³μ, bytes memory λ³μ) = .call{λ³΄λΌ μ΄λ}("ν¨μνΈμΆ").
- μ‘κΈλ§ νλ μν© call{value:λ³΄λΌ value}(""). ν¨μνΈμΆμ νμ§ μλλ€λ©΄ λ€μ ("")λΆλΆμ λΉμλλ€.
- ν¨μ νΈμΆλ§ νλ μν©.("")μ ""μμ λΆλ₯΄λ €λ ν¨μλ₯Ό κΈ°μ¬. μ΄λλ₯Ό 보λ΄μ§ μλλ€λ©΄ .call("")μ²λΌ {}λ₯Ό μλ΅ν ννκ° λ κ².
- λ¦¬ν΄ νμ μ (bool λ³μ, bytes memory λ³μ). λ§μ½ μ‘κΈλ§ νλ€λ©΄ μ½€λ§(,)λ€μ 'bytes memory λ³μ' λΆλΆμ λΉμλ . λ°λμ κ²½μ°λ https://www.youtube.com/watch?v=ax5lHvxL9dE 6λΆ ~ 9λΆ https://medium.com/coinmonks/solidity-transfer-vs-send-vs-call-function-64c92cfc878a (bool sent, bytes memory data) = _to.call.gas(10000){value: msg.value}("");
https://solidity-by-example.org/call/
https://ethereum.stackexchange.com/questions/96685/how-to-use-address-call-in-solidity
https://consensys.github.io/smart-contract-best-practices/development-recommendations/general/external-calls/
https://medium.com/coinmonks/solidity-transfer-vs-send-vs-call-function-64c92cfc878a
snapshot.
DAOμμλ μ΄λ€ μ μμ΄ λ€μ΄μ¬μ§λ₯Ό 미리 μκ³ ν΄λΉ μ μμ λ€ννλ νμμ λ§κΈ° μν΄ snapshotμ μ¬μ©νλ€.
μ€λ
μ·(snapshot)μ΄λ νΉμ ν μμ μμ κ° μ¬μ©μλ€μ΄ 보μ νκ³ μλ μνΈννμ μλμ "λ§μΉ μ¬μ§μ μ°λ―μ΄" λ³λλ‘ μ μ₯ν΄ λλ νμλ₯Ό λ§νλ€.
λΈλ‘μ²΄μΈ λ°μ΄ν°μ κ²½μ°μ νΉμ ν λΈλ‘μ κΈ°μ€μΌλ‘ λ°μ΄ν°λ₯Ό 볡μ¬νμ¬ μ μ₯νλ νμλ₯Ό μ€λ
μ·μ΄λΌκ³ νλ€.
μ€λ
μ· μΌμ μ΄ 14μΌμ΄κ³ μμ΄λλμ΄ 20μΌμ΄λΌκ³ κ°μ νλ€λ©΄ 14μΌ κΈ°μ€μΌλ‘ Aμ½μΈμ κ°μ§κ³ μμ΄μΌ Bμ½μΈμ 20μΌμ 무λ£λ‘ λ°μ μ μκ² λλ€. μ΄λ μ€λ
μ· λ μ§μΈ 14μΌλΆν° ν΄λΉ μ½μΈμ κ±°λλ μ€λ¨λκ³ μμ΄λλ μ€μμΌ 20μΌμ΄ λμμΌ κΈ°μ‘΄ μ½μΈκ³Ό μΆκ° μ½μΈμ΄ μμ₯μμ νμ±νλλ€.
http://wiki.hash.kr/index.php/%EC%8A%A4%EB%83%85%EC%83%B7
openzeppelin docs - Contract Wizard
erc20, erc721, erc1155 λ± νλ‘ν μ½μ μνλ κΈ°λ₯(mint, burn...)λ±μ UIλ‘ λ£μ΄μ μ€λ§νΈ 컨νΈλνΈλ₯Ό μ§€ μ μκ² ν΄μ€λ€.
https://docs.openzeppelin.com/contracts/4.x/wizard
Hardhat
Hardhat comes built-in with Hardhat Network, a local Ethereum network node designed for development.
It allows you to deploy your contracts, run your tests and debug your code, all within the confines of your local machine.
μμ½ : νλνμ μ체 λ‘컬 λ€νΈμν¬λ₯Ό λ΄μ₯ν λΌμ΄λΈλ¬λ¦¬λΌμ λ°λ‘λ°λ‘ λ§μ΄λλκ³ λ°°ν¬λλ€. λ
Έλ 1κ°μ§λ¦¬ λ€νΈμν¬λΌκ³ 보면 λ λ―
https://hardhat.org/hardhat-network/docs/overview
UTXO κ°λ
https://steemit.com/kr/@brownbears/utxo
μμ ν€μλ 'is'
https://merrily-code.tistory.com/103
this
_from == address(this) 쑰건μ ν¨μ λ΄μμ μ£Όμ(_from)κ° νμ¬ μ€λ§νΈ 컨νΈλνΈ(address(this))μ λμΌνμ§ νμΈνλ 쑰건μ
λλ€.
μ€λ§νΈ 컨νΈλνΈλ μ΄λ리μ λΈλ‘μ²΄μΈ μμ λ°°ν¬λλ νλ‘κ·Έλ¨μΌλ‘, μ체μ μΌλ‘ κ³μ½ λ‘μ§μ μ€ννκ³ μνΈμμ©ν μ μλ μν μ ν©λλ€. μ€λ§νΈ 컨νΈλνΈλ μ£Όμλ‘ μλ³λλ©°, address(this) ννμ νμ¬ μ€ν μ€μΈ μ€λ§νΈ 컨νΈλνΈμ μ£Όμλ₯Ό λνλ
λλ€.
λ°λΌμ _from == address(this) 쑰건μ ν¨μμ μ λ¬λ _from μ£Όμκ° νμ¬ μ€ν μ€μΈ μ€λ§νΈ 컨νΈλνΈμ μ£Όμμ λμΌνμ§ νμΈνλ κ²μ μλ―Έν©λλ€. μ¦, ν¨μ λ΄μμλ _from μ£Όμκ° μ€λ§νΈ 컨νΈλνΈ μ체μμ μ΄λ£¨μ΄μ§λ νΈλμμ
μ΄λΌλ©΄, _currency ν ν°μ _to μ£Όμλ‘ μμ νκ² μ μ‘ν©λλ€. μ΄λ μ€λ§νΈ 컨νΈλνΈμμ νΉμ ν ν°μ λ€λ₯Έ μ£Όμλ‘ μ μ‘νλ λ‘μ§μ ꡬννλ λ° μ¬μ©λ μ μμ΅λλ€.
ERC-20 ν ν° μ£Όμ ChatGPTμκ² ν μ§λ¬Έ : safeTransferERC20 ν¨μμ μΈμ address _currency κ° λμΌ?
safeTransferERC20 ν¨μμ μΈμ address _currencyλ ν ν°μ μ£Όμλ₯Ό λνλ
λλ€. μ΄ μ£Όμλ ERC-20 ν ν° μ»¨νΈλνΈμ μ£Όμλ₯Ό κ°λ¦¬ν΅λλ€.
ERC-20μ Ethereum κΈ°λ°μ ν ν° νμ€μΌλ‘, λ€μν ν ν°λ€μ΄ μ΄ νμ€μ λ°λΌ κ°λ°λκ³ λ°°ν¬λ©λλ€. κ°κ°μ ERC-20 ν ν°μ κ³ μ ν μ£Όμλ₯Ό κ°κ³ μμΌλ©°, μ΄ μ£Όμλ ν ν° μ»¨νΈλνΈλ₯Ό μλ³ν©λλ€.
safeTransferERC20 ν¨μμμ _currency μΈμλ μ λ¬λ°μ ν ν°μ μ£Όμλ₯Ό μλ―Έν©λλ€. μ΄ μ£Όμλ _from μ£Όμμμ _to μ£Όμλ‘ ν΄λΉ ν ν°μ μ μ‘ν λ μ¬μ©λ©λλ€. _currency μ£Όμμ ν΄λΉνλ ν ν° μ»¨νΈλνΈμ ν¨μλ₯Ό νΈμΆνμ¬ ν ν°μ μ μ‘νκ² λ©λλ€.
λ°λΌμ address _currencyλ safeTransferERC20 ν¨μμ λ§€κ°λ³μλ‘ μ λ¬λ ERC-20 ν ν°μ μ£Όμλ₯Ό λνλ΄λ©°, ν΄λΉ μ£Όμμ ν ν°μ μ μ‘νλ λ° μ¬μ©λ©λλ€.
ERC-20 ν ν°μ κ³ μ ν μ£Όμ μμλ₯Ό 2κ°
μ΄λ리μ (Ethereum) ν ν° μ£Όμ:
μ£Όμ: 0x0ETH
μ΄λ리μ λ©μΈ λ· (Mainnet)μμ λ°°ν¬λ ERC-20 ν ν°μ μ£Όμ μμμ
λλ€.
ν
λ (Tether) ν ν° μ£Όμ:
μ£Όμ: 0xdAC17F958D2ee523a2206206994597C13D831ec7
ν
λ(USDT)λ ERC-20 νμ€μ λ°λ₯΄λ μ€ν
μ΄λΈ μ½μΈμΌλ‘, μ μ£Όμλ λ©μΈ λ·μμ ν
λ ν ν° μ»¨νΈλνΈμ μ£Όμ μμμ
λλ€.
κ°κ°μ ERC-20 ν ν°μ κ³ μ ν μ£Όμλ₯Ό κ°μ§λ©°, μ΄ μ£Όμλ ν ν°μ μλ³μ μν μ ν©λλ€. μ΄λ¬ν μ£Όμλ₯Ό μ¬μ©νμ¬ ν ν° μ»¨νΈλνΈμ μ κ·Όνκ³ ν ν° κ΄λ ¨ μμ
μ μνν μ μμ΅λλ€.
μ μμλ ν ν° μ£Όμμ νμμ 보μ¬μ£Όλ μμμΌ λΏ, μ€μ μ¬μ©λλ ERC-20 ν ν°μ μ£Όμλ ν΄λΉ ν ν°μ λ°°ν¬μ κ΄λ ¨λ κ²μ
λλ€.
solidity import error(@openzeppelin λΉ¨κ° μ€)
juanfranblanco/vscode-solidity#70
settings.json -> "solidity.packageDefaultDependenciesDirectory": "node_modules" μ λ ₯