๐งก ERC721 Token
contract ERC721 {
event Transfer(address indexed _from, address indexed _to, uint256 _tokenId);
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
function balanceOf(address _owner) public view returns (uint256 _balance);
function ownerOf(uint256 _tokenId) public view returns (address _owner);
function transfer(address _to, uint256 _tokenId) public;
function approve(address _to, uint256 _tokenId) public;
function takeOwnership(uint256 _tokenId) public;
}
๐งก ERC721 Token Transfer
1. transfer ํจ์๋ ํ ํฐ์ ์์ ์๊ฐ ์ ์ก ์๋์ address, ์ ์กํ๊ณ ์ ํ๋ tokenId๋ฅผ ๋๊ฒจ์ฃผ๋ ๋ฐฉ์์ด๋ค.
2. approve ํจ์๋ ์์์ ๋ณธ ์ ๋ณด๋ค์ ๊ฐ๊ณ ํธ์ถํ๋ ๋ฐฉ์์ด๋ค. ๊ทธ๋ฆฌ๊ณ ์ปจํธ๋ํธ์ ๋๊ฐ ํด๋น ํ ํฐ์ ๊ฐ์ง ์ ์๋๋ก ํ๊ฐ๋ฅผ ๋ฐ์๋์ง ์ ์ฅํ๋ค. ๊ทธ๋ฆฌ๊ณ ๋๊ตฐ๊ฐ๊ฐ takeOnwership ํจ์๋ฅผ ํธ์ถํ๋ฉด ํด๋น ์ปจํธ๋ํธ๋ msg.sender๊ฐ ์์ ์๋ก๋ถํฐ ํ ํฐ์ ๋ฐ์ ์ ์๊ฒ ํ๊ฐ๋ฅผ ๋ฐ์๋์ง ํ์ธํ๋ค.
function transfer(address _to, uint256 _tokenId) public;
function approve(address _to, uint256 _tokenId) public;
function takeOwnership(uint256 _tokenId) public;
๐งก OpenZeppelin SafeMath Library
Solidity์์๋ ๋ฒํผ์ค๋ฒํ๋ก์ฐ๋ฅผ ๋ง๊ธฐ ์ํด OpenZeppelin์์ ์ง์ํ๋ SafeMath ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํด์ผ ํ๋ค.
using SafeMath for uint256;
uint256 a = 5;
uint256 b = a.add(3); // 5 + 3 = 8
uint256 c = a.mul(2); // 5 * 2 = 10
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
https://share.cryptozombies.io/ko/lesson/5/share/H4XF13LD_MORRIS_๐ฏ๐ฏ๐๐ฏ๐ฏ?id=Y3p8MTIwMjIz
'Solidity' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[CryptoZombie] 1-4 Zombie Battle System (0) | 2021.08.02 |
---|---|
[CryptoZombie] 1-3 Advanced Solidity Concepts (0) | 2021.07.22 |
[CryptoZombie] 1-2 Zombies Attack Their Victims (0) | 2021.07.22 |
[CryptoZombie] 1-1 Making the Zombie Factory (0) | 2021.07.22 |
[Chap4] ์ค๋งํธ ์ปจํธ๋ํธ์ ๊ฐ๋ (0) | 2021.07.16 |