블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12....
Transcript of 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12....
![Page 1: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/1.jpg)
묶음 강좌명 : 블록체인
12. 블록체인 실습 : ERC 2.012-1. ERC20 개요 및 API 소개
블록체인응용과 실습
![Page 2: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/2.jpg)
1. ERC 20
2. 블록체인(비트코인) 플랫폼 명령어
사용법 안내
블록체인 플랫폼 명령어의 사용법을
설명할 수 있다.
![Page 3: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/3.jpg)
1. ERC 20
![Page 4: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/4.jpg)
토큰 (Token)
토큰 이코노미에서 가치의 저장 및 척도, 교환의 수단
트랜잭션 실행, 데이터 전송, 채굴에 대한 보상 등에사용 가능
자산, 수수료, 참가비, 보상 등 다양한 곳에 사용 가능
토큰 이코노미 설계시, 플랫폼 혹은 Dapp의 지속적인가치가 증가하도록 구현하는 것이 중요함
![Page 5: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/5.jpg)
ERC20
Ethereum Request for Comment 20
이더리움 블록체인 네트워크에서 발행되는 토큰의 표준
Dapp
• ERC20 토큰 표준을 따름
![Page 6: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/6.jpg)
토큰(Token)
https://etherscan.io/ 우측 상단 검색창에OmiseGO 입력
![Page 7: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/7.jpg)
토큰(Token)
검색결과
OmiseGo
OmiseGo Token
Normal 계정
Smart Contract 계정
Open payment platform, decentralized exchange center
전통적인 은행 시스템 이용자와 은행 시스템 인프라, 접근이 어려운
개발도상국 사람들에게 공통 서비스 제공을 취지로 함
![Page 8: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/8.jpg)
ERC20 Categorizing
![Page 9: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/9.jpg)
토큰 등록하기
ERC20 표준을 준수하면 이더스캔에 토큰 등록 가능
EIP(Ethereum Improvement Proposal)를 통해서도 관리 가능
![Page 10: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/10.jpg)
ERC20 Tokens 사례
https://etherscan.io/tokens(약 860개 ERC20)
![Page 11: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/11.jpg)
ERC20 Tokens
Ethereum.org Example
https://www.ethereum.org/token
BAT’s Token : Basic Attention TokenGet paid to view ads, pay content producers.
https://basicattentiontoken.org/brave-users-get-rewarded-to-browse/
AUGUR’s Token : Decentralized Prediction MarketPeople ‘vote’ on what actually happened
http://etherscan.io/address/0xe94327d07fc17907b4db788e5adf2ed424addff6#code
참고 https://bitcoin.org/ko/download
![Page 12: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/12.jpg)
Ropsten 테스트넷 이용
Faucet에서 이더 배급 받아 사용
• http://faucet.ropsten.be:3001/
• 미스트 안에서 계정 2개 사용하여 테스트 함
이더스캔으로 블록 정보 확인(테스트넷)
• https://testnet.etherscan.io/
![Page 13: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/13.jpg)
Ropsten 테스트넷 이용
mytoken.sol 찾아서 Mist 브라우저에 C&P
• https://github.com/chrisdannen/Introducing-Ethereum-and-Solidity/
토큰만들기
토큰보기
![Page 14: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/14.jpg)
ERC20 표준에 부합하는 최소한의 인터페이스
// ----------------------------------------------------------------------------// ERC Token Standard #20 Interface// ----------------------------------------------------------------------------contract ERC20Interface { function totalSupply() public view returns (uint); function balanceOf(address tokenOwner) public view returns (uintbalance); function allowance(address tokenOwner, address spender) publicview returns (uint remaining); function transfer(address to, uint tokens) public returns (boolsuccess); function approve(address spender, uint tokens) public returns (boolsuccess); function transferFrom(address from, address to, uint tokens) publicreturns (bool success);
event Transfer(address indexed from, address indexed to, uinttokens); event Approval(address indexed tokenOwner, address indexedspender, uint tokens);}
• 현재까지 공급된 토큰수
• owner가 보유한 토큰잔액을 반환함
• 토큰 소유자(_owner)가 토큰수신자(_spender)에게 인출을 허락한토큰이 얼마인지를 반환함
• 수신자(_to) 로 해당금액(_value)를송금함
• 송신자(msg.sender)가 보유한토큰에서 일정금액(_value)만큼의토큰을 인출할수 있는 권한을수신자(_spender)에게 부여함
• 송신자(_from)주소에서 수신자(_to) 주소로 해당금액(_value)을 송금함
![Page 15: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/15.jpg)
ERC20 함수를 통한 토큰 거래 예시(1/4)
Balances라는 데이터 구조(배열)을 통해 각 사용자의잔액을 유지함
balances[0x1111111111111111111111111111111111111111] = 100 balances[0x2222222222222222222222222222222222222222] = 200
ERC20 balanceOf() 함수를 사용하여 이러한 값을 확인할수 있음
tokenContract.balanceOf(0x1111111111111111111111111111111111111111) will return 100 tokenContract.balanceOf(0x2222222222222222222222222222222222222222) will return 200
![Page 16: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/16.jpg)
ERC20 함수를 통한 토큰 거래 예시(2/4)
0x2222 … 에게 10 토큰을 전송함
tokenContract.transfer(0x2222222222222222222222222222222222222222, 10)
잔액 변화
balances[0x1111111111111111111111111111111111111111] = 90 balances[0x2222222222222222222222222222222222222222] = 210
![Page 17: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/17.jpg)
ERC20 함수를 통한 토큰 거래 예시(3/4)
0x1111 … 이 0x2222 … 에게 30 토큰까지 가져갈 수있도록 허용함
tokenContract.approve(0x2222222222222222222222222222222222222222, 30)
추후 0x222 … 가 0x1111 … 로부터 20토큰을 가져오고싶다면
tokenContract.transferFrom(0x1111111111111111111111111111111111111111, 0x2222222222222222222222222222222222222222, 20)
![Page 18: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/18.jpg)
ERC20 함수를 통한 토큰 거래 예시(4/4)
잔액변화
tokenContract.balances[0x1111111111111111111111111111111111111111] = 70 tokenContract.balances[0x2222222222222222222222222222222222222222] = 230
여전히 내부 자료구조에는 30-20 = 10 토큰 송금 허용된상태
tokenContract.allowed[0x1111111111111111111111111111111111111111][0x2222222222222222222222222222222222222222] = 10
![Page 19: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/19.jpg)
2. 토큰발행예시
![Page 20: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/20.jpg)
나만의 토큰 발행하기
소스 코드 복사
• https://ethereum.org/token의 2번째 코드
컴파일 (0.5.3+commit)
Deploy 시 발행량, 토큰이름, 토큰심볼 기재 필요
1000, “MIN”, MN”
![Page 21: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/21.jpg)
나만의 토큰 발행하기
![Page 22: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/22.jpg)
배포된 ERC20 컨트랙트 인터페이스
파랑색 : Cell 함수
• 가스 소모되지 않음
빨강색 : sendTransaction
• 이더리움 네트워크의 상태를 변경시키고 가스 비용을 지불하는 함수
![Page 23: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/23.jpg)
배포된 ERC20 컨트랙트 인터페이스
![Page 24: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/24.jpg)
Metamask에 ‘토큰 추가’
![Page 25: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/25.jpg)
Metamask에 ‘토큰 추가’
![Page 26: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/26.jpg)
Metamask에 ‘토큰 추가’
![Page 27: 블록체인응용과실습 - kmooc.kr€¦ · 묶음강좌명: 블록체인 12. 블록체인실습: erc 2.0 12-1. erc20 개요및api 소개 블록체인응용과실습](https://reader035.fdocuments.co/reader035/viewer/2022062403/60471052ea03db39db40092c/html5/thumbnails/27.jpg)
ICO를 위한 토큰 발행 준비
토큰 전송 기능, 권한 분배, 해킹 등 비상 사태가 발생했을 때대처하기 위한 기능, DApp 개발 후에 포크를 위한 대비 등
Minime 토큰
• Anybody can create a new clone token from any token using this contract with an initial distribution identical to the original token at a specified block.
• The address calling the createCloneToken function will become the token controller and the token's default settings can be specified in the function call.
참고 https://github.com/Giveth/minime