[TIL] 2023-05-26 DAY48
GIT 주소 : https://github.com/dowoo303/SOLIDITY
오늘 배운것들
- ERC20
1) MintToken 실험
2) 사기유형파악- ERC721(NFT)
- 연사 초청강연
각종 팁
- ERC20, 721, 157 함수들은 기본적으로 함수 실행자(대부분 오너로 작동)+인풋 값을 잘 파악하면 읽기 쉽다.
회고
- NFT거래소가 내 NFT를 상대방에게 전달해주는 것이 아닌 직접적인 전달이다. 다만, 실행을 해주는 권한(approve)을 NFT거래소에게 줘서 작동하게 만듬.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
contract LIONTOKEN is ERC20("LIKE LION", "LL") { // 54번째 줄 constructor 설정
// 배포하자마자 토큰을 mint해서 모든 발행량을 내 지갑으로 들어오도록 설정
constructor(uint totalSupply) {
_mint(msg.sender, totalSupply); // totalSupply 변경
}
// 내 지갑 잔고 확인
function getBalance() public view returns(uint) {
return balanceOf(msg.sender);
}
function MintToken(uint a) public {
_mint(address(this), a);
}
// decimasl 3(10**-3)으로 override
function decimals() public pure override returns (uint8) {
return 3;
}
// 기본적으로 ERC20은 약속임 -> 그래서 서로 약속된 함수 이름만 보이면 그러려니 하고 받아옴
receive() external payable{}
}
// 이름이랑 심볼 변경
contract TRASH is ERC20("Trash", "1") {
constructor() {
// _mint(msg.sender, totalSupply);
owner = msg.sender;
}
address public owner;
mapping(address => uint256) private _balances;
bool goodMind = true;
function changeGoodMind() public {
require(owner == msg.sender, "you are not owner");
goodMind = false;
}
function name() public view override returns(string memory) {
return "REALTRASH";
}
function symbol() public view override returns(string memory) {
return "RT";
}
function decimals() public pure override returns (uint8) {
return 0;
}
function _mint(address account, uint _a) internal override {
account = msg.sender;
_balances[account] += _a;
}
function MINT(uint _a) public {
_mint(msg.sender, _a);
}
// 지갑잔고 500 계속 고정도 가능
function balanceOf(address account) public view override returns(uint) {
if(goodMind) {
return _balances[account];
} else {
return 0; // _transfer(피해자 주소, 사기꾼 주소, 피해금액)
}
}
}
OpenZeppelin: https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/contracts/token/ERC721
기본 ERC721(NFT) 코드에 대하여 학습
내일은 블체스 3기 첫 외부 연사님 특강이 진행됩니다!
현업 블록체인 분야에서의 다양한 경험과 관점을 들어볼 수 있는 시간입니다.
일시 : 5/26(금) 16시 ~ 18시
연사 : Raf 님
현 블록체인 랩스 Blockchain Engineer
현 폴카닷 Technical Ambassador