티스토리 뷰

뭔데, 조선말! 뭔데... 한국어라고 해줘.. 코리안이라고.. Korean..
크립토 좀비 Beginner 과정을 진행해 봐야지... 작은 게임을 만들면서 배우는거라고 한다..
챕터 하나씩 쉽게 쉽게 만들어져 있다 (지금 기본이라 그런듯)
코드 정답 맞추면 이런 화면이 뜬다.

아주 뿌듯하다...
pragma solidity >=0.5.0 <0.6.0;
contract ZombieFactory {
uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;
struct Zombie {
string name;
uint dna;
}
Zombie[] public zombies;
// start here
}
우선 지금까지 배운거 대충 보면, 변수 정의하는거 uint (unsigned int) 이런거 비슷하구...
그리고 struct 는 파이썬에서 클래스랑 비슷하다.
재밌군..?
챕터 12까지 하면 다음과 같은 솔리디티 코드가 생긴다.
스트럭트도 만들고, 함수도 private, public 방식으로 만들고..
pragma solidity >=0.5.0 <0.6.0;
contract ZombieFactory {
// declare our event here
uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;
struct Zombie {
string name;
uint dna;
}
Zombie[] public zombies;
function _createZombie(string memory _name, uint _dna) private {
zombies.push(Zombie(_name, _dna));
// and fire it here
}
function _generateRandomDna(string memory _str) private view returns (uint) {
uint rand = uint(keccak256(abi.encodePacked(_str)));
return rand % dnaModulus;
}
function createRandomZombie(string memory _name) public {
uint randDna = _generateRandomDna(_name);
_createZombie(_name, randDna);
}
}
keccak256 이라는 해쉬 함수도 알게되고..
이제 event도 배웠다.
pragma solidity >=0.5.0 <0.6.0;
contract ZombieFactory {
// declare our event here
uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;
struct Zombie {
string name;
uint dna;
}
Zombie[] public zombies;
function _createZombie(string memory _name, uint _dna) private {
zombies.push(Zombie(_name, _dna));
// and fire it here
}
function _generateRandomDna(string memory _str) private view returns (uint) {
uint rand = uint(keccak256(abi.encodePacked(_str)));
return rand % dnaModulus;
}
function createRandomZombie(string memory _name) public {
uint randDna = _generateRandomDna(_name);
_createZombie(_name, randDna);
}
}
이렇게 나의 좀비가 만들어졌다.
https://share.cryptozombies.io/en/lesson/1/share/mar?id=Y3p8NjU3MTQ1
Check out my CryptoZombie OGURL!
I just completed CryptoZombies Lesson 1 and learned the basics of coding a game on Ethereum. Take a look at the first zombie in my army! Thanks @CryptoZombiesHQ.
share.cryptozombies.io
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- DART
- til
- 터틀포인트
- 플러터
- web2
- web2web3비교
- 이더리움
- setState
- 길리
- 오블완
- 김영한
- 길리여행
- 테스트넷
- 티스토리챌린지
- 선라이즈 패들보트
- 패들보트
- web3
- contains
- zksync
- 찾아봄
- 솔리디티
- 세상만사새옹지마
- prettier
- 세폴리아
- 공부좀열심히해라
- Flutter
- vscode
- 스파르타코딩클럽
- gili
- 크립토좀비
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함