SlideShare a Scribd company logo
1 of 112
Download to read offline
예제로 배우는
스마트 컨트랙트
프로그래밍
( 오재훈 jaehoon@nethru.co.kr )
Byzantium Megara Geth1.7
ethereum 연구회
Lab 0. 실습 준비
ethereum 연구회
Step 1. Mist 설치하기
1. Mist 다운로드
• https://github.com/ethereum/mist/releases
• Mac 용 : mist-macosx-0-9-2.dmg
• Windows 용 : mist-installer-0-9-2.exe
2. Mist 설치 하기
3. Mist 실행하기
• Mist 를 실행하면, node 를 실행하기 위한 바이너리들을
설치하기 시작한다.
• 설치가 종료되면 오른쪽 화면이 나타난다.
• geth 클라이언트를 다운로드 했는지 확인한다.
• Mac : ~/Library/Application
Support/Mist/binaries/Geth/unpacked/geth
• Windows : C:Users사용자계정
AppDataRoamingMistbinariesGethunpackedgeth
• Mist 를 종료한다.
ethereum 연구회
Traditional Contract
https://www.slideshare.net/philippecamacho/smart-contractsethereum 연구회
Smart Contract
https://www.slideshare.net/philippecamacho/smart-contractsethereum 연구회
Solidity
Ethereum 스마트 컨트랙을 개발할 때 가장 많이 사용되는 언어
문법은 자바 언어와 유사함
객체지향 언어
정적 타입언어
스코프 : Function Scope ( 참고 : Block Scope )
ethereum 연구회
256 비트 가상 머신
스택기반 머신
Turing Complete
Ethereum Virtual Machine
Program
Counter
PUSH1 0
CALLDATALOAD
SLOAD
NOT
PUSH1 9
JUMPI
STOP
JUMPDEST
PUSH1 32
CALLDATALOAD
PUSH1 0
CALLDATALOAD
SSTORE
Memory
...
StorageStack
Call Data
Log
ethereum 연구회
Halting Problem - Gas Cost Model
https://docs.google.com/spreadsheets/d/1m
89CVujrQe5LAFJ8-
YAUCcNK950dUzMQPMJBxRtGCqs/edit#gi
d=0
ethereum 연구회
Halting Problem - Gas Cost Model
Data Location Gas 비용
Storage 32바이트당 20,000
Memory 32바이트당 1
Log 32바이트당 96 ( 바이트당 3 )
Call Data Zero 바이트 : 4
Non-zero 바이트 : 68
https://ethereum.stackexchange.com/questions/3/what-is-meant-by-the-term-gas
Program
Counter
PUSH1 0
CALLDATALOAD
SLOAD
NOT
PUSH1 9
JUMPI
STOP
JUMPDEST
PUSH1 32
CALLDATALOAD
PUSH1 0
CALLDATALOAD
SSTORE
Memory
...
StorageStack
Call Data
Log
ethereum 연구회
Lab 1. 계정 생성 + 마이닝
ethereum 연구회
Step 1. geth 클라이언트 실행하기
Mac
$ cd ~/Documents/Ethereum/privatenet
$ GETH=”~/Library/Application Support/Mist/binaries/Geth/unpacked/geth”
$ “$GETH” --ipcpath test-net/geth.ipc --datadir test-data --dev
Windows
cmd> cd C:Users사용자계정AppDataRoamingMistbinariesGethunpacked
cmd> C:Users사용자계정AppDataRoamingMistbinariesGethunpacked> geth --ipcpath test-
net/test.ipc --datadir test-data --dev
ethereum 연구회
Step 2. geth console attach
새 터미널(커맨드 창)을 띄워서 geth console 을 실행한다.
Mac
$ cd ~/Documents/Ethereum/privatenet
$ GETH=”~/Library/Application Support/Mist/binaries/Geth/unpacked/geth”
$ “$GETH” attach test-net/geth.ipc
Windows
cmd> cd C:Users사용자계정AppDataRoamingMistbinariesGethunpacked
cmd> C:Users사용자계정AppDataRoamingMistbinariesGethunpacked>
cmd>geth attach //./pipe/test-net/test.ipc
ethereum 연구회
Step 3. Mist 실행
새로운 터미널에서 Mist 을 아래와 같이 실행한다.
Mac
$ cd ~/Documents/Ethereum/privatenet
$ /Applications/Mist.app/Contents/MacOS/Mist --rpc test-net/geth.ipc
Windows
C:Program FilesMist>Mist --rpc //./pipe/test-net/test.ipc
ethereum 연구회
Step 4. 계정 생성
계정 생성 방법
1. Mist 에서 생성하기
2. Geth console 에서 생성하기
Geth console 에서 계정 생성하기
> eth.accounts
[]
> personal.newAccount()
Passphrase: <Enter your password>
Repeat passphrase: <Enter your password>
"0xfb7198ad789c69c771f5cfb20f2d4978bd918e2c"
> eth.accounts
["0xfb7198ad789c69c771f5cfb20f2d4978bd918e2c"]
>
ethereum 연구회
Step 4. Mist 에서 계정 생성 확인
신규 계정이 생성되면 Mist 에 Main
Account 가 표시된다.
0xfb7198ad789c69c771f5cfb20f2d4978bd918e2c
ethereum 연구회
Step 5. Mining 제어하기
Geth console 에서 마이닝
제어하기
• 마이닝 시작 :
miner.start()
• 마이닝 중지 :
miner.stop()
ethereum 연구회
Step 5. Mining 결과확인
마이닝을 시작하면 Main
계정에 Ether 가 쌓이기
시작한다.
ethereum 연구회
Lab 2. 이더 송금하기
ethereum 연구회
Step 1. 계정 추가하기
다른 계정으로 이더(ether)를 송금해 보자.
이더를 송금하려면 계정이 두 개 이상 필요하다.
1. 계정을 만들 때, 테스트를 쉽게 하려면
Main 계정과 같은 암호를 사용하는 것이
좋다.
2. Geth console 에서 추가로 계정을 하나 만
든다. ( 계정 생성 참조 )
3. 생성된 계정이 Wallet 에 표시되는지 확인
한다.
Wallet 에서 “계정 추가"를 클릭해서 계정을 추가
할 수도 있다.
ethereum 연구회
Step 2. 수신 계정 선택
1. 새로 추가한 계정(“Account
2”) 를 클릭한다.
2. 오른쪽 윗부분에 있는 “이
더 입금”을 클릭한다.
ethereum 연구회
Step 3. 송금하기
1. Geth console 에서 마이닝을 중지한다. ( miner.stop() )
2. 금액에 “100” (이더) 를 입력한다.
3. “보내기”를 클릭한다.
4. “Send Transaction” 화면에서 계정의 비밀번호를 입력
한다.
5. “Send Transaction” 을 클릭한다.100
암호 입력
ethereum 연구회
Step 4. 송금 진행
송금을 요청하면 자동으로 “지갑" 화면으로 이동한다.
1. 지갑 화면 아래쪽에 송금 요청한 트랜잭션이 표시되는
지 확인한다.
2. geth console 에서 마이닝을 시작한다. ( miner.start() )
3. Mist 화면에서 트랜잭션에 대한 동의가 일어나는 과정
을 확인한다.
ethereum 연구회
Step 5. 송금 확인
트랜잭션이 완료되면 “승인 정보”가 표시되던 자리에
트랜잭션이 요청된 시간이 표시된다.
트랜잭션을 클릭해서 트랜잭션의 상세 정보를 확인한다.
클릭해서 상세정보 확인
트랜잭션 비용
ethereum 연구회
Step 5. 계좌 잔액 확인
지갑 화면에서 “Account 2” 의 잔액 확인한다.
Geth console 에서 mining 멈춘다.
ethereum 연구회
트랜잭션
이더리움 트랜잭션
• EOA(External Owned Account) 가 다른 계정으로
보내는 메시지
트랜잭션에 포함되는 정보
1. 수신자(recipient)
2. 송신자(sender)를 식별할 수 있는 시그너쳐
3. 송신 금액(value)
4. 데이터 필드(선택사항) : 컨트랙에 보내는 메시지
5. Startgas : 최대로 소비할 수 있는 가스량
6. Gasprice : 수신자가 지불할 가스당 이더
트랜잭션 종류
• 송금 트랜잭션
• 컨트랙트 생성 트랜잭션 ( 수신자 주소가 0 )
ethereum 연구회
Lab 3. Token Contract 만들기
ethereum 연구회
Token
이더리움 에코 시스템에서 유동성있고 교환가능한 상품
- 예 : 코인, 마일리지 포인트, 금 소유 확인증
토큰 컨트랙트
• 토큰을 관리하기 위한 컨트랙트
• 발행 토큰 량, 토큰 장부(계정, 잔액) 관리, 송금, 인출 등을 지원함
2017년 10월 현재 Ethereum ERC20 토큰 수 : 10,565
https://etherscan.io/tokens
총 발행량 : 1,000
토큰 컨트랙트
계정 잔액
0xAB... 100
0xCD... 200
0xEF... 300
ethereum 연구회
Minimum Viable Token
pragma solidity ^0.4.16;
contract MinimumViableToken {
/* This creates an arraywith all balances */
mapping (address => uint256) public balanceOf;
/* Initializes contract with initial supply tokens to the creator of the contract */
function MinimumViableToken(uint256 initialSupply) {
balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
}
/* Send coins */
function transfer(address _to, uint256 _value) {
balanceOf[msg.sender] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
}
}
https://gist.github.com/xbill82/9136c10da3414437a2000642d88d3b0d
ethereum 연구회
Smart Contract 구조
pragma solidity ^0.4.16;
contract MinimumViableToken {
/* This creates an arraywith all balances */
mapping (address => uint256) public balanceOf;
/* Initializes contract with initial supply tokens to the creator of the contract */
function MinimumViableToken(uint256 initialSupply) {
balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
}
/* Send coins */
function transfer(address _to, uint256 _value) {
balanceOf[msg.sender] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
}
}
State Variables
Constructor
Functions
Version Pragma
ethereum 연구회
Step 1. 컨트랙트 생성 화면으로 이동
1. 컨트랙트 버튼 클릭
2. 신규 컨트랙트 설치 버튼 클릭
ethereum 연구회
Step 2. 소스 코드 복사
MinimumViableToken 코드를 “솔리디티 컨
트랙트 소스 코드"로 복사한다.
컨트랙트 코드 컴파일에 문제가 없으면, 오
른쪽 화면에 “컨트랙트 선택" 창이 나타난다.
ethereum 연구회
Step 3. Token 컨트랙트 설치
1. “컨트랙트 선택" 을 클릭한다.
2. “Minimum Viable Token” 선택한다.
3. Initial Supply 를 1000 으로 입력한다.
4. 화면을 아래로 스크롤해서 “설치" 클릭
한다.
1000
ethereum 연구회
Step 4. Token 컨트랙트 생성 Sign 하기
컨트랙트 생성을 요청하면 “Create Contract” 창이
뜨고 계정의 암호를 묻는다.
1. 계정 암호를 입력한다.
2. SEND TRANSACTION 버튼 클릭한다.
계정 암호 입력
클릭
ethereum 연구회
Step 5. 토큰 컨트랙트 트랜잭션 확인
컨트랙트를 생성하면, 지갑에 컨트랙트 생성
트랜잭션이 추가된다.
트랜잭션이 마이닝되지 않으면 트랜잭션이
승인되지 않은 상태로 있다.
1. Geth console 에서 “miner.start()” 명령
어로 miner 를 동작시킨다.
2. 트랜잭션이 동의과정을 거쳐서 승인이
되는 것을 확인한다.
3. 트랜잭션 처리가 완료된 것을 확인한
다.
ethereum 연구회
Step 5. 컨트랙트 생성 트랜잭션 확인
토큰 컨트랙 생성 트랜잭션이 완료되면 트랜잭션 상세 내용
을 살펴본다.
트랜잭션 비용
• 송금 트랜잭션 : 21,000
• 컨트랙트 생성 트랜잭션 비용 : 21,000 + α
Gas Price
• https://etherscan.io/chart/gasprice
트랜잭션 비용
ethereum 연구회
트랜잭션이 종료되면 생성된 컨트랙트를 클
릭하여 컨트랙트 상세 화면으로 이동한다.
주소를 더블 클릭한 후 복사한다.
Step 6. Token 컨트랙트 확인
ethereum 연구회
지금 생성한 Minimum Viable Token 은 여러가지 문제를 가지고 있다.
1. 토큰 생성자에게 1000 토큰을 부여했지만, Mist 화면에 표시되지 않는다.
a. 토큰 생성자가 자신이 토큰을 소유했다는 사실을 알기 어렵다.
1. 토큰을 전송하는 함수(transfer)에서 조건을 검사하지 않는다.
a. 송신자가 자신이 가진 토큰보다 더 많은 토큰을 전송할 수 있다.
b. 토큰 수신자가 보유한 토큰에 Overflow 가 발생하면, 토큰이 모두 사라질 수 있다.
Minimum Viable Token 의 문제
ethereum 연구회
Minimum Viable Token 은 지갑에 바로 등록되지 않기 때문
에 토큰 잔액을 확인하기 어렵다.
Minimum Viable Token 의 잔액을 지갑에서 확인하려면, 토
큰을 수동으로 추가해야 한다.
1. “컨트랙트” 링크를 클릭한다.
2. 아래쪽으로 스크롤해서 “토큰 추가" 버튼을 클릭한다.
3. 토큰 컨트랙트 추가 화면에서 다음과 같이 입력한다.
a. “토큰 컨트랙트 주소”에 좀전에 복사한 주소를
입력
b. 토큰이름 : First Minimum Viable Token
c. 토큰심볼 : FMVTs
d. 최소단위 십진 자리수 : 0
4. 확인을 클릭한다.
Step 7. Token 추가하기
ethereum 연구회
토큰이 추가되면, Minimum Viable Token 을 생성한
계정에 토큰 잔액이 표시된다.
1. “지갑" 링크를 클릭한다.
2. 컨트랙트를 생성한 계정을 클릭한다.
3. 컨트랙트를 생성한 계정의 “First Minimum
Viable Token” 잔액이 1000 FMVT 인지 확인한
다.
Step 8. 보유 토큰 확인
ethereum 연구회
Step 9. 토큰 송금하기
계정 잔액
Main Account 1,000
계정 잔액
Main Account 500
Account 2 500
ethereum 연구회
토큰도 이더와 마찬가지 방법으로 다른 계정에 송금할
수 있다. Main 계정에서 Account 2 로 500 FMVTs 를
송금해보자.
1. Account 2 계정을 클릭한다.
2. “이더 입금" 을 클릭한다.
3. “금액" 에 500을 입력한다.
4. “First Minimum Viable Token” 을 클릭한다.
송금이 완료되면 송금 결과확인한다.
1. Main 계정을 클릭해서 잔액을 확인한다.
2. Account 2 계정을 클릭해서 잔액을 확인한다.
Step 9. 토큰 송금하기
ethereum 연구회
토큰 컨트랙트 함수를 불러서 토큰을 전송할 수도 있
다. Main 계정에서 “Account 2” 로 토큰을 100개 전송
해 보자.
1. “컨트랙트”를 클릭한다.
2. “Minimum Viable Token” 컨트랙트를 클릭한다.
3. “컨트랙트에 쓰기" 에서 “함수 선택"을 클릭한다.
4. “to - address” 에 “Account 2” 계정의 주소를 입
력한다.
5. “value” 에 600 을 입력한다.
6. “Execute from” 에서 “Main Account” 를 선택한
다.
7. 실행을 클릭한다.
Step 10. 컨트랙트 함수 부르기
Account 2 주소
600
ethereum 연구회
Step 9. 토큰 송금하기
계정 잔액
Main Account ?
Account 2 1,100
계정 잔액
Main Account 500
Account 2 500
ethereum 연구회
Smart Contract 구조
pragma solidity ^0.4.16;
contract MinimumViableToken {
/* This creates an arraywith all balances */
mapping (address => uint256) public balanceOf;
/* Initializes contract with initial supply tokens to the creator of the contract */
function MinimumViableToken(uint256 initialSupply) {
balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
}
/* Send coins */
function transfer(address _to, uint256 _value) {
balanceOf[msg.sender] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
}
}
State Variables
Constructor
Functions
Version Pragma
ethereum 연구회
Smart Contract 구조
항목 설명
version pragma Solidity 컴파일러 버전의 호환성을 지정한다.
state variable 컨트랙트에 저장할 상태 변수들을 선언한다.
constructor 컨트랙트의 생성자. 컨트랙트가 생성될 때 딱 1번 실행된다.
function EOA 나 컨트랙트, 컨트랙트 내부에서 부를 수 있는 함수를 정의한다.
function modifier 반복적으로 사용되는 조건을 정의하기 위해서 사용한다.
Smart Contract 는 다음과 같은 부분으로 구성되어 있다.
ethereum 연구회
Version Pragma
표현 설명
<1.2.7 1.2.7 미만
<=1.2.7 1.2.7 이하
>1.2.7 1.2.7 초과
>=1.2.7 1.2.7 이상
=1.2.7 1.2.7 만
1.2.7 =1.2.7 과 동일
1.2.7 || 1.2.8 1.2.7 이나 1.2.8
>=1.2.9 <2.0.0 1.2.9 보다 크거나 같고, 2.0.0 미만
https://docs.npmjs.com/misc/semver
ethereum 연구회
State Variables
컨트랙트 내부에서 정의된 변수들
이더리움의 영구 스토리지에 저장됨 ( 키/값 구조 )
Gas 가 상대적으로 많이 소모됨
가시성 설명
public 모두가 접근할 수 있고, Getter function 이 자동으로 생성됨
ex ) string public name;
internal 컨트랙트(혹은 컨트랙트를 상속하는 컨트랙트) 내부에서만 사용할 수 있음
private 컨트랙트 내부에서만 접근 가능함. 상속한 컨트랙트에서는 사용 불가
ethereum 연구회
Types
Value Types bool,
int8, int16, int24, int32, …, int256
uint8, uint16, uint24, uint32,..., uint256
address
정적 배열 : bytes1 (byte), byte2, byte3, …, bytes32
동적 배열 : bytes, string
enum
function
Reference Types 배열(array), 구조체(struct)
Data location 을 지정할 수 있음 : storage 혹은 memory
데이터를 복사하는 비용이 많이 들 수 있기 때문에 어디에 저장할지 선택해야 함
http://solidity.readthedocs.io/en/develop/types.html
ethereum 연구회
Data Location
모든 complex type(array 나 struct) 은 data location 을 가지고 있다.
• Data Location : memory, storage
변수 컨텍스트 기본 변경
State variable storage 불가능
Local variable storage 가능
함수 패러미터 memory 가능
함수 반환값 memory 가능
Program Counter
PUSH1 0
CALLDATALOAD
SLOAD
NOT
PUSH1 9
JUMPI
STOP
JUMPDEST
PUSH1 32
CALLDATALOAD
PUSH1 0
CALLDATALOAD
SSTORE
Memory
...
Storage
Stack
Call Data
Log
ethereum 연구회
Data Location
Data location 에 따라 assignment 가 다르게 동작함
독립적인 복사본을 생성하는 assignment
- Storage 와 메모리 사이의 assignment
- State variable 을 변경하는 assignment
참조만을 복사하는 assignment
- Local storage 에 대한 assignment
- Memory 에 저장된 reference type 에서 memory 에 저장된 reference type
으로 assign 하면 복사본을 만들지 않는다.
ethereum 연구회
Functions
Function Type 설명
View Function State 를 바꾸지 않는(상태를 Write 하지 않는) 함수는 view 로 선언할 수 있다.
Pure Function State 를 읽거나 바꾸지 않는 함수를 pure 로 선언할 수 있다.
Fallback Function 이름이 없는 함수. 패러미터가 없어야 하고, 반환값도 없어야 한다.
컨트랙의 함수를 불렀는데, 지정한 함수가 존재하지 않을 때 불린다.
Function Modifier Python 의 decorator / Java 의 AOP 와 유사함
function name(<parameter types>)
[internal|external|public|private]
[pure|constant|view|payable]
[returns (<return types>)] {
...
}
ethereum 연구회
Functions - 상태 Write
아래의 경우 상태가 변경된다고 가정
1. state variable 에 기록하기
2. event 를 발생시키기
3. 다른 컨트랙 생성하기
4. selfdestruct 사용하기
5. call 을 통해서 Ether 보내기
6. view/pure 함수가 아닌 함수를 부르기
7. EVM 의 call 을 사용하기
8. 특정 opcode 를 포함하는 인라인 assembly 사용하기
ethereum 연구회
Functions - 상태 Read
아래의 경우 상태가 변경된다고 가정
1. state variable 을 읽기
2. this.balance 를 접근하거나 <address>.balance 를 읽기
3. block, tx, msg 의 멤버 접근하기 ( msg.data, msg.sig 제외 )
4. pure 로 선언되지 않은 함수를 부르기
5. 어떤 opcode 를 포함하는 인라인 어셈블리를 사용하기
ethereum 연구회
Function Visibility
Function Visibility 타입 : external, public, internal, private (생략하면 public)
Visibility 설명
external EOA(External Owned Account) 에서만 부를 수 있음
데이터가 클 때 유리함 ( CallData 를 메모리로 복사하지 않기 때문)
public EOA, 다른 컨트랙트, 컨트랙트 내부에서 부를 수 있음
EOA 가 public 메소드를 부르면 많은 비용이 발생함
( CallData 를 메모리로 복사하기 때문에 )
internal 컨트랙트(혹은 컨트랙트를 상속하는 컨트랙트) 내부에서만 부를 수 있음
private 컨트랙트 안에서만 부를 수 있음 ( 상속한 컨트랙트에서는 부를 수 없음 )
ethereum 연구회
Function Visibility
EOA
Contract
function balanceOf() public
function balanceOf1() external
function balanceOf() internal
function balanceOf() private
Another Contract
function balanceOf() public
function balanceOf1() external
function balanceOf() internal
function balanceOf() private
Parent Contract
function balanceOf() public
function balanceOf1() external
function balanceOf() internal
function balanceOf() private
Transaction External Call
(Message)
Internal Call
ethereum 연구회
Function Modifier
• 반복되는 논리를 한 곳에서 관리하기 위한 방법
• python 의 decorator
• Java 의 AOP 와 유사함
• Ether 를 전송받는 함수에는 반드시 payable modifier 를 지정해야 함
modifier onlyOwner {
require(msg.sender ==
owner);
_;
}
function open() onlyOwner {
open = true;
}
function close() onlyOwner {
open = false;
}
function open() {
require(msg.sender ==
owner);
open = true;;
}
function close() {
require(msg.sender ==
owner);
open = false;
}
ethereum 연구회
Special Variables - msg
변수 타입 설명
msg.sender account 메시지 송신자
msg.value uint 메시지와 함께 전송된 ether
양
msg.gas uint 남은 가스
msg.sig bytes4 calldata 의 첫번째 4 바이트
msg.data bytes calldata 전체
ethereum 연구회
Lab 4. Wallet Visible Token
ethereum 연구회
Wallet Visible Token
pragma solidity ^0.4.16;
contract WalletVisibleToken {
mapping (address => uint256) public balanceOf;
event Transfer(address _from, address _to, uint _value);
function WalletVisibleToken(uint256 initialSupply) {
balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
}
function transfer(address _to, uint256 _value) {
balanceOf[msg.sender] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
Transfer(msg.sender,_to,_value);
}
}
Events
ethereum 연구회
Step 1. Wallet Visible Token 만들기
Mission : Wallet Visible Token 컨트랙트를 생성한다.
( 과정은 Minimum Viable Token 생성과 동일하다. )
• Initial Supply 는 “2000” 으로 지정
토큰 생성이 완료되면 Main 계정 토큰 잔액을 확인한다.
• 토큰 이름, 토큰 심벌 등 토큰에 대한 정보를 지정하
지 않았기 때문에, undefined 로 표시된다.
ethereum 연구회
Step 2. 토큰 정보 수정
새로 생성된 토큰 정보를 수정한다.
1. “컨트랙트"를 클릭한다.
2. “주문형 토큰" 에서 “UNDEFINED ...” 인 토
큰을 클릭한다.
3. 토큰 수정 화면에서 다음과 같이 입력한다.
a. 토큰 이름 : Wallet Visible Token
b. 토큰 심벌 : WVTs
c. 최소단위 십진수 : 0
4. 확인을 클릭해서 토큰 정보를 등록한다.
ethereum 연구회
Step 3. 토큰 송금
계정 잔액
Main Account 1,000
계정 잔액
Main Account 900
Account 2 100
Main Account 에서 Account 2 로 100 토큰을 송금하자
ethereum 연구회
Step 4. 트랜잭션 이벤트 확인
다음과 같이 트랜잭션 이벤트를 확인한다.
1. “Wallet Visible Token” 컨트랙트를 선
택한다.
2. 화면을 아래쪽으로 스크롤해서 “계약
이벤트를 보기" 를 클릭한다.
3. 방금전에 송금할 때 발생한 Event 가
기록되었는지 확인한다.
ethereum 연구회
Step 5. Transfer 함수 실행
Wallet Visible Token 의 Transfer 함수를 이
용해서 “Account 2” 로 50 토큰을 송금해 보
자.
• “이더 입금" 에서 전송한 이벤트와
Transfer 함수를 부른 이벤트가 동일
한 것을 확인할 수 있다.
확인이 끝나면, “계약 이벤트를 보기" 옵션
을 끈다.
ethereum 연구회
Events
• EVM logging 기능을 이용하도록 설계된 장치
• 블록체인의 transaction log 에 패러미터와 함께 기록된다.
• 컨트랙 내부에서는 접근할 수 없음
• 정의: 컨트랙트 안에서 선언
• event Transfer(address _from, address _to, uint _value);
• event Transfer(address indexed _from, address indexed _to, uint _value);
• 사용: 컨트랙트 함수에서
• Transfer(_from, _to, _value); Program
Counter
PUSH1 0
CALLDATALOAD
SLOAD
NOT
PUSH1 9
JUMPI
STOP
JUMPDEST
PUSH1 32
CALLDATALOAD
PUSH1 0
CALLDATALOAD
SSTORE
Memory
.
.
.
StorageStack
Call Data
Log
ethereum 연구회
Events
1. 트랜잭션을 생성한 Application 에 결과값을 반환하는 용도
2. 트랜잭션을 생성한 Application 을 Trigger 하기 위해서
3. 히스토리 데이터를 저장하기 위한 용도
a.Log 영역은 Storage 영역에 비해 비용이 아주 저렴
b.Event 의 패러미터 세개까지 indexed 를 지정할 수 있음
c.indexed 패러미터를 이용해서 검색에 사용할 수 있음
ethereum 연구회
Require & Revert
pragma solidity ^0.4.16;
contract UnsecureToken {
mapping (address => uint256) public balanceOf;
function UnsecureToken(uint256 initialSupply) {
balanceOf[msg.sender] = initialSupply;
}
function transfer(address _to, uint256 _value) {
if (balanceOf[_to] + _value < balanceOf[_to]) return;
balanceOf[_to] += _value;
if (balanceOf[msg.sender] < _value) return;
balanceOf[msg.sender] -= _value;
}
}
pragma solidity ^0.4.16;
contract UnsecureToken {
mapping (address => uint256) public balanceOf;
function UnsecureToken(uint256 initialSupply) {
balanceOf[msg.sender] = initialSupply;
}
function transfer(address _to, uint256 _value) {
if (balanceOf[_to] + _value < balanceOf[_to]) return;
if (balanceOf[msg.sender] < _value) return;
balanceOf[_to] += _value;
balanceOf[msg.sender] -= _value;
}
}
ethereum 연구회
Require & Revert
pragma solidity ^0.4.16;
contract UnsecureToken {
mapping (address => uint256) public balanceOf;
function UnsecureToken(uint256 initialSupply) {
balanceOf[msg.sender] = initialSupply;
}
function transfer(address _to, uint256 _value) {
if (balanceOf[_to] + _value < balanceOf[_to]) return;
if (balanceOf[msg.sender] < _value) return;
balanceOf[_to] += _value;
balanceOf[msg.sender] -= _value;
}
}
pragma solidity ^0.4.16;
contract SecureToken {
mapping (address => uint256) public balanceOf;
function UnsecureToken(uint256 initialSupply) {
balanceOf[msg.sender] = initialSupply;
}
function transfer(address _to, uint256 _value) {
if (balanceOf[_to] + _value < balanceOf[_to]) revert();
balanceOf[_to] += _value;
if (balanceOf[msg.sender] < _value) revert();
balanceOf[msg.sender] -= _value;
}
}
ethereum 연구회
Require & Revert
pragma solidity ^0.4.16;
contract SecureToken {
mapping (address => uint256) public balanceOf;
function UnsecureToken(uint256 initialSupply) {
balanceOf[msg.sender] = initialSupply;
}
function transfer(address _to, uint256 _value) {
if (balanceOf[_to] + _value < balanceOf[_to]) revert();
balanceOf[_to] += _value;
if (balanceOf[msg.sender] < _value) revert();
balanceOf[msg.sender] -= _value;
}
}
pragma solidity ^0.4.16;
contract SecureToken {
mapping (address => uint256) public balanceOf;
function UnsecureToken(uint256 initialSupply) {
balanceOf[msg.sender] = initialSupply;
}
function transfer(address _to, uint256 _value) {
if (balanceOf[_to] + _value < balanceOf[_to]) revert();
if (balanceOf[msg.sender] < _value) revert();
balanceOf[_to] += _value;
balanceOf[msg.sender] -= _value;
}
}
ethereum 연구회
Require & Revert
pragma solidity ^0.4.16;
contract SecureToken {
mapping (address => uint256) public balanceOf;
function UnsecureToken(uint256 initialSupply) {
balanceOf[msg.sender] = initialSupply;
}
function transfer(address _to, uint256 _value) {
require(balanceOf[msg.sender] >= _value);
require(balanceOf[_to] + _value >= balanceOf[_to]);
balanceOf[_to] += _value;
balanceOf[msg.sender] -= _value;
}
}
pragma solidity ^0.4.16;
contract SecureToken {
mapping (address => uint256) public balanceOf;
function UnsecureToken(uint256 initialSupply) {
balanceOf[msg.sender] = initialSupply;
}
function transfer(address _to, uint256 _value) {
if (balanceOf[_to] + _value < balanceOf[_to]) revert();
if (balanceOf[msg.sender] < _value) revert();
balanceOf[_to] += _value;
balanceOf[msg.sender] -= _value;
}
}
ethereum 연구회
Lab 5. Mist 호환 토큰
ethereum 연구회
Wallet Compatible Token
pragma solidity ^0.4.16;
contract WalletCompatibleToken {
string public constant name = "Wallet Compatible Token";
string public constant symbol = "WCTs";
uint8 public constant decimals = 18;
mapping (address => uint256) public balanceOf;
event Transfer(address _from, address _to, uint _value);
function WalletCompatibleToken(uint256 initialSupply) {
balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
}
function transfer(address _to, uint256 _value) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
require(balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows
balanceOf[msg.sender] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
Transfer(msg.sender,_to,_value);
}
}
ethereum 연구회
Step 1. Wallet Compatible Token 만들기
Mission : Wallet Compatible Token 컨트랙트를 생성한다.
( 과정은 Minimum Viable Token 생성과 동일하다. )
• Initial Supply 는 “3,000,000,000,000,000,000,000”
으로 지정
토큰 생성이 완료되면 Main 계정 토큰 잔액을 확인한다.
토큰 잔액이 왜 “3 000” 밖에 되지 않을까?
ethereum 연구회
Decimals
Solidity 는 부동 소수점 연산을 제공하지 않고 정수만을 사용해서 계산함
decimals 는 소수점 자리수를 정의함
사용자에게 토큰을 표시할 때 소수점 자리수를 이용해서 보여줌
Token Decimals Total Tokens
10,000 0 10,000
10,000 1 1,000.0
10,000 2 100.00
1,000,000,000,000,000,000 18 1.00000 00000 00000 000
ethereum 연구회
Decimals
Ether는 decimals 이 18이다.
• 이더는 모두 wei 단위로 저장되고 관리된다.
• Szabo, Finney, Ether 로 지정해도 실제로는 wei 단
위로만 기록된다.
단위 Wei
wei 1
K wei 1,000 wei
M wei 1,000,000 wei
G wei 1,000,000,000 wei
Szabo 1,000,000,000,000 wei
Finney 1,000,000,000,000,000 wei
Ether 1,000,000,000,000,000,000 wei
ethereum 연구회
Lab 6. Mist 호환 토큰2
ethereum 연구회
pragma solidity ^0.4.16;
contract WalletCompatibleToken {
string public name;
string public symbol;
uint8 public decimals;
mapping (address => uint256) public balanceOf;
event Transfer(address _from, address _to, uint _value);
function WalletCompatibleToken(string tokenName,string tokenSymbol,uint8 decimalUnits,uint256 initialSupply) {
name = tokenName;
symbol = tokenSymbol;
decimals = decimalUnits;
balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
}
...
}
Wallet Compatible Token
ethereum 연구회
Step 1. Wallet Compatible Token 만들기
Mission : Wallet Compatible Token 컨트랙트를 생
성한다.
( 과정은 Minimum Viable Token 생성과 동일하다.
)
• Initial Supply 는
“3,000,000,000,000,000,000,000” 으로 지정
토큰 생성이 완료되면 Main 계정 토큰 잔액을 확
인한다.
토큰 잔액이 왜 “3 000” 밖에 되지 않을까?
ethereum 연구회
ERC20 Token Standard
contract ERC20 {
function totalSupply() constant returns (uint totalSupply);
function balanceOf(address _owner) constant returns (uint balance);
function transfer(address _to, uint _value) returns (bool success);
function transferFrom(address _from, address _to, uint _value) returns (bool success);
function approve(address _spender, uint _value) returns (bool success);
function allowance(address _owner, address _spender) constant returns (uint remaining);
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
}
https://theethereum.wiki/w/index.php/ERC20_Token_Standardethereum 연구회
Lab 7. CrowdFund
ethereum 연구회
Crowd Fund
1980년 5월, 서울 택시운전사. “광주? 돈 워리, 돈 워리! 아이 베스트 드라이버”
택시운전사 만섭(송강호)은 외국손님을 태우고 광주에 갔다 통금 전에 돌아오면
밀린 월세를 갚을 수 있는 거금 10만원을 준다는 말에
독일기자 피터(토마스 크레취만)를 태우고 영문도 모른 채 길을 나선다.
광주 그리고 사람들. “모르겄어라, 우덜도 우덜한테 와 그라는지…”
어떻게든 택시비를 받아야 하는 만섭의 기지로 검문을 뚫고 겨우 들어선 광주.
위험하니 서울로 돌아가자는 만섭의 만류에도
피터는 대학생 재식(류준열)과 황기사(유해진)의 도움 속에 촬영을 시작한다.
그러나 상황은 점점 심각해지고 만섭은 집에 혼자 있을 딸 걱정에 점점 초조해지
는데…
ethereum 연구회
여러분은 영화 “택시 운전사" 제작을 위한 크라우드 펀드 스마트 컨트랙트를 만들어야 합니다. 택시 운전사
를 제작하기 위해서는 최소 500 이더가 필요합니다.
요구사항
1. 모금 기간은 분단위로 지정된다.
2. EOA 가 펀드에 청약하면, 청약한 금액에 해당되는 증표(토큰)을 발행한다.
3. 청약 금액과 증표 비율은 1:1로 한다.
4. 모금 기간안에 모금 목표 금액을 달성하면 영화제작사에게 모금금액을 모두 송금한다.
5. 모금 기간이 지나도 모금 목표 금액이 달성되지 않으면 청약자들에게 청약한 금액을 모두 반환한다.
CrowdFund 컨트랙트
ethereum 연구회
Crowd Fund
A
B
C
D
계정 잔액
택시 운전사
제작사
(beneficiary)
목표금액: 500 이더
A 100
B 50
C 200
D 150
ethereum 연구회
Crowd Fund
100 이더
A
100 토큰
계정 이더 잔액
Crowd
Fund
Token Contract
A 에게 토큰 송
금
A 100
계정 토큰 잔액
A 100
ethereum 연구회
1. Main 계정에서 WalletCompatibleToken.sol 을 이용해서 Taxi Driver Fund 를 위한 토큰을 만든다.
a. Name : TaxiDriver Token
b. Symbol : TDs
c. Decimal Units : 0
d. Initial Supply : 1000
2. Main 계정의 “TaxiDriver Token” 잔액이 1,000인지 확인한다.
3. TaxiDriver Token 의 주소를 복사해 둔다.
Step 1. TaxiDriver Token 생성하기
ethereum 연구회
Step 2. CrowdFund 컨트랙트 생성하기
CrowdFund.sol 을 이용해서 새로운 컨트랙트를 생성한다. 생
성자 패러미터는 다음과 같이 입력한다.
1. If successful send to : Main account 가 아닌 계정
2. Funding goal in ethers : 200
3. Duration in minutes : 10
4. Ether cost of each token : 1
5. Address of token used ad reward : Step1 에서 만든 컨트
랙트의 주소
ethereum 연구회
Step 3. CrowdFund 로 송금
“Account 2” CowdFund 컨트랙트로 송금을 시도하자.
1. “컨트랙트" 를 클릭해서 컨트랙트 목록을 표시한다.
2. CrowdFund 컨트랙트를 클릭한다.
3. “이더 입금"을 클릭한다.
4. 금액에 100을 입력한다.
5. “전송" 버튼을 클릭한다.
6. 왼쪽과 같은 Send Transaction 화면이 뜨는지 확인한다.
ethereum 연구회
Step 4. CrowdFund 에 토큰 송금
EOA 에서 CrowdFund 에 송금했을 때, TaxiDriver Token 을 보상으로
제공하려면 CrowdFund 가 TaxiDriver Token 을 보유해야 한다.
보유한 토큰의 50%인 500 토큰을 CrowdFund 컨트랙트로 송금한다.
1. 컨트랙트 버튼을 클릭한다.
2. CrowdFund 컨트랙을 생성한다.
3. 이더 입금을 클릭한다.
4. “송신처" 계정을 선택한다. ( TaxiDriver Token 을 생성한 계정 )
5. 금액에 500을 입력한다.
6. 전송을 클릭한다.
ethereum 연구회
Step 5. CrowdFund 보유 토큰 확인
아래와 같이 CrowdFund 보유 토큰을 확인한다.
1. CrowdFund 컨트랙트의 주소를 복사한다.
2. “컨트랙트" 를 클릭해서 컨트랙트 목록을 표시
한다.
3. “TaxiDriver” 컨트랙트를 클릭한다.
4. “Balance of” 에 CrowdFund 컨트랙트 주소를
복사한다.
5. 보유 잔액이 500인지 확인한다.
CrowdFund 주소
잔액이 표시됨
ethereum 연구회
Step 6. CrowdFund 청약
“Account 2” CowdFund 컨트랙트로 송금을 시도하자.
1. “컨트랙트" 를 클릭해서 컨트랙트 목록을 표시한다.
2. CrowdFund 컨트랙트를 클릭한다.
3. “이더 입금"을 클릭한다.
4. 금액에 100을 입력한다.
5. “전송" 버튼을 클릭한다.
6. Send Transaction 화면이 오류 없이 뜨는지 확인한다.
7. 암호를 입력하고 “Send Transaction” 을 클릭한다.
ethereum 연구회
Step 7. CrowdFund 청약 결과 확인
“지갑" 을 클릭한 후 “Account 2” 계정에서 다음을 확인한다.
1. “100 TDs” 가 입금되었다.
2. “100” 이더가 감소하였다.
ethereum 연구회
pragma solidity ^0.4.16;
interface token {
function transfer(address receiver, uint amount);
}
contract CrowdFund {
address public beneficiary;
uint public fundingGoal;
uint public amountRaised;
uint public deadline;
uint public price;
token public tokenReward;
mapping(address => uint256) public balanceOf;
bool fundingGoalReached = false;
bool crowdsaleClosed = false;
CrowdFund
ethereum 연구회
CrowdFund 컨트랙트
변수 설명
beneficiary 펀드가 모였을 때, 펀드를 받을 수신자
계정
fundingGoal 펀드 목표 금액( 이더 )
amountRaised 펀드 청약 금액 (이더)
deadline 펀드 모금 기간 (초)
price 이더와 토큰 교환 비율
tokenReward 토큰 컨트랙트
balanceOf 펀드 청약 장부
fundingGoalReached 펀드 목표 금액 도달 여부
crowdsaleClosed 펀드 청약 기한 종료 여부
ethereum 연구회
CrowdFund
event GoalReached(address beneficiaryAddress, uint amountRaisedValue);
event FundTransfer(address backer, uint amount, bool isContribution);
function CrowdFund(
address ifSuccessfulSendTo,
uint fundingGoalInEthers,
uint durationInMinutes,
uint etherCostOfEachToken,
address addressOfTokenUsedAsReward
) {
beneficiary = ifSuccessfulSendTo;
fundingGoal = fundingGoalInEthers * 1 ether;
deadline = now + durationInMinutes * 1 minutes;
price = etherCostOfEachToken * 1 ether;
tokenReward = token(addressOfTokenUsedAsReward);
}
ethereum 연구회
function () payable {
require(!crowdsaleClosed);
uint amount = msg.value;
balanceOf[msg.sender] += amount;
amountRaised += amount;
tokenReward.transfer(msg.sender, amount / price);
FundTransfer(msg.sender, amount, true);
}
modifier afterDeadline() { if (now >= deadline) _; }
function checkGoalReached() afterDeadline {
if (amountRaised >= fundingGoal){
fundingGoalReached = true;
GoalReached(beneficiary, amountRaised);
}
crowdsaleClosed = true;
}
CrowdFund
ethereum 연구회
CrowdFund
function safeWithdrawal() afterDeadline {
if (!fundingGoalReached) {
uint amount = balanceOf[msg.sender];
balanceOf[msg.sender] = 0;
if (amount > 0) {
if (msg.sender.send(amount)) {
FundTransfer(msg.sender, amount, false);
} else {
balanceOf[msg.sender] = amount;
}
}
}
if (fundingGoalReached && beneficiary == msg.sender) {
if (beneficiary.send(amountRaised)) {
FundTransfer(beneficiary, amountRaised, false);
} else {
fundingGoalReached = false;
}
}
}
}ethereum 연구회
Step 8. CrowdFund 인출하기
기간이 만료되면 CrowdFund 컨트랙트의
CheckGoalReached 를 부른다.
1. “컨트랙트" 버튼을 클릭한다.
2. “함수 선택" 을 클릭한다.
3. “CheckGoalReached” 를 선택한다.
4. “실행" 을 클릭한다.
ethereum 연구회
Step 8. CrowdFund 인출하기
기간이 만료되면 CrowdFund 컨트랙트의
CheckGoalReached 를 부른다.
1. “컨트랙트" 버튼을 클릭한다.
2. “함수 선택" 을 클릭한다.
3. “SafeWithdrawal” 를 선택한다.
4. “실행" 을 클릭한다.
ethereum 연구회
Special Keywords
Special Keywords
Ether Units wei, finney, szabo, ether
● 1 ether == 1000 finney
● 1 finney == 1000 szabo
● 1 szabo == 1000,000,000,000 wei
Time Units seconds, minutes, hours, days, weeks, years
● 1 == 1 seconds
● 1 minutes == 60 seconds
● 1 hours == 60 minutes
● 1 days == 24 hours
● 1 weeks == 7 days
● 1 years == 365 days
ethereum 연구회
Special Variables - block & transaction
변수 타입 설명
block.coinbase address 현재 블록의 마이너 주소
block.difficulty uint 현재 블록의 difficulty
block.gaslimit uint 현재 블록의 gaslimit
block.number uint 현재 블록 넘버
block.timestamp uint 현재 블록의 timestamp (초)
block.blockhash(blockNumber) bytes32 주어진 블록의 해쉬값. 현재 블록을 포함해서 최근 256개 블록에서만 동작
변수 타입 설명
tx.gasprice uint 트랜잭션의 gas price
tx.origin address 트랜잭션 송신자
ethereum 연구회
Address
변수 및 함수 타입 설명
address.balance uint256 주소의 잔액 ( Wei 단위로 )
address.transfer(uint256 amount) 주어진 주소로 amount 만큼의 Wei 를 보낸다. 실패하면 throw
address.send(uint256 amount) bool 주어진 주소로 amount 만큼의 Wei 를 보낸다. 실패하면 false 반환. 실패시
처리로직을 구현해야 함
address.call(...) bool 임의의 컨트랙에 있는 함수를 불러야할 때 사용한다.
EVM 의 CALL 을 부른다. 실패하면 false 를 반환한다.
- ether 값 지정 가능 : address.call.value(1 ether)(...)
- gas 값 지정 가능 : address.call.gas(100000)(...)
address.calldata(...) bool EVM 의 CALLCODE 를 부른다. 실패하면 false 를 반환
- gas(), value() 옵션 사용가능
address.delegatecall(...) bool EVM 의 DELEGATECALL 을 부른다. 실패하면 false 를 반환
call 과 동일하지만, 불린 함수에서 현재 컨트랙의 storage, balance 등을 사
용
다른 컨트랙에 있는 코드를 라이브러리로 사용할 때 필요함
- gas() 옵션 사용가능, value() 옵션은 사용할 수 없읍
ethereum 연구회
Lab 8. Remix를 이용한
Debugging
ethereum 연구회
Step 0. Remix IDE 열기
Remix IDE 를 이용해서 스마트 컨
트랙을 개발하고 설치할 수도 있다
.
1. Mist 메뉴 창에서 “개발"을
클릭
2. “Remix IDE 열기" 메뉴 클릭
ethereum 연구회
Remix IDE 는 파일탐색기, 편집기
, 터미널, 탭 판넬로 구성된다.
Step 0. Remix IDE 창 구조
터미널 (Terminal)
편집기 (Editor)
(파일탐색기
File
Explorer)
탭 판넬(Tabs
Panel)
https://remix.readthedocs.io/en/latest/
ethereum 연구회
Step 1. 기존 컨트랙트 실행하기
Remix IDE 에서 기존 컨트랙트를 사용할 수 있다.
1. 탭 판넬에서 Run 탭을 클릭한다.
2. Environment 에서 Injected Web3 를 선택
한다.
3. Mist 메인화면에서 “First Minimum Viable
Token” 컨트랙트의 주소를복사한다.
4. At Address 에 “First Minimum Viable
Token” 컨트랙트의 주소를입력한다.
5. “At Address” 를 클릭한다.
6. balanceOf 에 Main 계정 주소를 입력한다.
7. balanceOf 를 클릭해서 계정의 잔액을 확인
한다.
컨트랙트 주
소
Main 계정 주
소
ethereum 연구회
Step 2. 디버그 하기
디버그 버튼을 누른다.
ethereum 연구회
Lab 9. Remix 스마트 컨트랙트생성
ethereum 연구회
Step 1. 컨트랙트 파일 생성
다음 과정을 이용해서 컨트랙트 파일을
생성한다.
1. 파일탐색기 왼쪽 위에 있는 “파일
생성" 버튼을 클릭한다.
2. File Name 에
“MinimumViableToken.sol” 을 입
력한다.
ethereum 연구회
Step 2. 컨트랙트 입력
다음 과정을 이용해서 컨트랙트 파일을
생성한다.
1. 편집창에 Minimum Viable Token
소스를 복사한다.
2. Compile 탭에서 컴파일 과정에서
경고가 나오는지 확인한다.
3. 함수의 Visibility 를 명시하지 않
았기 때문에 issue 가 발생한다.
4. 함수 이름 뒤에 visibility 지정자로
public 을 입력한다.
ethereum 연구회
Step 3. 컨트랙트 생성하기
Run 탭에서 다음과 같이 컨트랙트를 신
규로 생성한다.
1. Run 탭을 클릭한다.
2. Create 창 옆에 initialSupply 를
10000 으로 입력한다.
3. Create 버튼을 클릭한다.
4. balancOf 창에 Main 계정을 입력
한다. ( 계정 입력시 :
"22eb0718c892e4ca9aed56811b
4ca8ca9b8314f6” 형식)
5. balanceOf 를 클릭한다.
ethereum 연구회
오늘 배운 것
● EVM 구조
● Gas Cost Model
● Smart Contract 구조
● Event / Log
● Transaction vs Message
● ERC20 Compatible Token
● Smart Contract 작성하는 법
● Remix 사용법
ethereum 연구회
감사합니다.

More Related Content

What's hot

세션5. web3.js와 Node.js 를 사용한 dApp 개발
세션5. web3.js와 Node.js 를 사용한 dApp 개발세션5. web3.js와 Node.js 를 사용한 dApp 개발
세션5. web3.js와 Node.js 를 사용한 dApp 개발Jay JH Park
 
Blockchain Study(2) - POW&POS
Blockchain Study(2) - POW&POSBlockchain Study(2) - POW&POS
Blockchain Study(2) - POW&POSFermat Jade
 
Blockchain 3rd smart contract programming
Blockchain 3rd smart contract programmingBlockchain 3rd smart contract programming
Blockchain 3rd smart contract programmingihpark92
 
Blockchain 4th dapp programming
Blockchain 4th dapp programmingBlockchain 4th dapp programming
Blockchain 4th dapp programmingihpark92
 
Blockchain 1st bitcoin_core
Blockchain 1st bitcoin_coreBlockchain 1st bitcoin_core
Blockchain 1st bitcoin_coreihpark92
 
Blockchain Study(3) - 이더리움(Geth)
Blockchain Study(3) - 이더리움(Geth)Blockchain Study(3) - 이더리움(Geth)
Blockchain Study(3) - 이더리움(Geth)Fermat Jade
 
Ethereum Basics Part 2
Ethereum Basics Part 2Ethereum Basics Part 2
Ethereum Basics Part 2Soobok Jin
 
Block chain introduction slideshare
Block chain introduction   slideshareBlock chain introduction   slideshare
Block chain introduction slidesharewonyong hwang
 
Dapp시연 150214
Dapp시연 150214Dapp시연 150214
Dapp시연 150214Jihong Shim
 
예제로 배우는 이더리움 결제구현 (거래소 지갑 구현 예시)
예제로 배우는 이더리움 결제구현 (거래소 지갑 구현 예시)예제로 배우는 이더리움 결제구현 (거래소 지갑 구현 예시)
예제로 배우는 이더리움 결제구현 (거래소 지갑 구현 예시)Colin Chae
 
GCGC- CGCII 서버 엔진에 적용된 기술 (2) - Perfornance
GCGC- CGCII 서버 엔진에 적용된 기술 (2) - PerfornanceGCGC- CGCII 서버 엔진에 적용된 기술 (2) - Perfornance
GCGC- CGCII 서버 엔진에 적용된 기술 (2) - Perfornance상현 조
 
GCGC- CGCII 서버 엔진에 적용된 기술 (5) - Executor with Exception
GCGC- CGCII 서버 엔진에 적용된 기술 (5) - Executor with ExceptionGCGC- CGCII 서버 엔진에 적용된 기술 (5) - Executor with Exception
GCGC- CGCII 서버 엔진에 적용된 기술 (5) - Executor with Exception상현 조
 
하이퍼레저 패브릭 데이터 구조
하이퍼레저 패브릭 데이터 구조하이퍼레저 패브릭 데이터 구조
하이퍼레저 패브릭 데이터 구조Logpresso
 
GCGC- CGCII 서버 엔진에 적용된 기술 (4) - Executing System
GCGC- CGCII 서버 엔진에 적용된 기술 (4) - Executing SystemGCGC- CGCII 서버 엔진에 적용된 기술 (4) - Executing System
GCGC- CGCII 서버 엔진에 적용된 기술 (4) - Executing System상현 조
 
GCGC- CGCII 서버 엔진에 적용된 기술 (8) - Group System
GCGC- CGCII 서버 엔진에 적용된 기술 (8) - Group SystemGCGC- CGCII 서버 엔진에 적용된 기술 (8) - Group System
GCGC- CGCII 서버 엔진에 적용된 기술 (8) - Group System상현 조
 
GCGC- CGCII 서버 엔진에 적용된 기술 (6) - CGCII Server Sample
GCGC- CGCII 서버 엔진에 적용된 기술 (6) - CGCII Server SampleGCGC- CGCII 서버 엔진에 적용된 기술 (6) - CGCII Server Sample
GCGC- CGCII 서버 엔진에 적용된 기술 (6) - CGCII Server Sample상현 조
 
하이퍼레저 패브릭 실습자료
하이퍼레저 패브릭 실습자료하이퍼레저 패브릭 실습자료
하이퍼레저 패브릭 실습자료TIMEGATE
 
GCGC- CGCII 서버 엔진에 적용된 기술 (1)
GCGC- CGCII 서버 엔진에 적용된 기술 (1)GCGC- CGCII 서버 엔진에 적용된 기술 (1)
GCGC- CGCII 서버 엔진에 적용된 기술 (1)상현 조
 
11_웹서비스활용
11_웹서비스활용11_웹서비스활용
11_웹서비스활용noerror
 
Multithread design pattern
Multithread design patternMultithread design pattern
Multithread design pattern종빈 오
 

What's hot (20)

세션5. web3.js와 Node.js 를 사용한 dApp 개발
세션5. web3.js와 Node.js 를 사용한 dApp 개발세션5. web3.js와 Node.js 를 사용한 dApp 개발
세션5. web3.js와 Node.js 를 사용한 dApp 개발
 
Blockchain Study(2) - POW&POS
Blockchain Study(2) - POW&POSBlockchain Study(2) - POW&POS
Blockchain Study(2) - POW&POS
 
Blockchain 3rd smart contract programming
Blockchain 3rd smart contract programmingBlockchain 3rd smart contract programming
Blockchain 3rd smart contract programming
 
Blockchain 4th dapp programming
Blockchain 4th dapp programmingBlockchain 4th dapp programming
Blockchain 4th dapp programming
 
Blockchain 1st bitcoin_core
Blockchain 1st bitcoin_coreBlockchain 1st bitcoin_core
Blockchain 1st bitcoin_core
 
Blockchain Study(3) - 이더리움(Geth)
Blockchain Study(3) - 이더리움(Geth)Blockchain Study(3) - 이더리움(Geth)
Blockchain Study(3) - 이더리움(Geth)
 
Ethereum Basics Part 2
Ethereum Basics Part 2Ethereum Basics Part 2
Ethereum Basics Part 2
 
Block chain introduction slideshare
Block chain introduction   slideshareBlock chain introduction   slideshare
Block chain introduction slideshare
 
Dapp시연 150214
Dapp시연 150214Dapp시연 150214
Dapp시연 150214
 
예제로 배우는 이더리움 결제구현 (거래소 지갑 구현 예시)
예제로 배우는 이더리움 결제구현 (거래소 지갑 구현 예시)예제로 배우는 이더리움 결제구현 (거래소 지갑 구현 예시)
예제로 배우는 이더리움 결제구현 (거래소 지갑 구현 예시)
 
GCGC- CGCII 서버 엔진에 적용된 기술 (2) - Perfornance
GCGC- CGCII 서버 엔진에 적용된 기술 (2) - PerfornanceGCGC- CGCII 서버 엔진에 적용된 기술 (2) - Perfornance
GCGC- CGCII 서버 엔진에 적용된 기술 (2) - Perfornance
 
GCGC- CGCII 서버 엔진에 적용된 기술 (5) - Executor with Exception
GCGC- CGCII 서버 엔진에 적용된 기술 (5) - Executor with ExceptionGCGC- CGCII 서버 엔진에 적용된 기술 (5) - Executor with Exception
GCGC- CGCII 서버 엔진에 적용된 기술 (5) - Executor with Exception
 
하이퍼레저 패브릭 데이터 구조
하이퍼레저 패브릭 데이터 구조하이퍼레저 패브릭 데이터 구조
하이퍼레저 패브릭 데이터 구조
 
GCGC- CGCII 서버 엔진에 적용된 기술 (4) - Executing System
GCGC- CGCII 서버 엔진에 적용된 기술 (4) - Executing SystemGCGC- CGCII 서버 엔진에 적용된 기술 (4) - Executing System
GCGC- CGCII 서버 엔진에 적용된 기술 (4) - Executing System
 
GCGC- CGCII 서버 엔진에 적용된 기술 (8) - Group System
GCGC- CGCII 서버 엔진에 적용된 기술 (8) - Group SystemGCGC- CGCII 서버 엔진에 적용된 기술 (8) - Group System
GCGC- CGCII 서버 엔진에 적용된 기술 (8) - Group System
 
GCGC- CGCII 서버 엔진에 적용된 기술 (6) - CGCII Server Sample
GCGC- CGCII 서버 엔진에 적용된 기술 (6) - CGCII Server SampleGCGC- CGCII 서버 엔진에 적용된 기술 (6) - CGCII Server Sample
GCGC- CGCII 서버 엔진에 적용된 기술 (6) - CGCII Server Sample
 
하이퍼레저 패브릭 실습자료
하이퍼레저 패브릭 실습자료하이퍼레저 패브릭 실습자료
하이퍼레저 패브릭 실습자료
 
GCGC- CGCII 서버 엔진에 적용된 기술 (1)
GCGC- CGCII 서버 엔진에 적용된 기술 (1)GCGC- CGCII 서버 엔진에 적용된 기술 (1)
GCGC- CGCII 서버 엔진에 적용된 기술 (1)
 
11_웹서비스활용
11_웹서비스활용11_웹서비스활용
11_웹서비스활용
 
Multithread design pattern
Multithread design patternMultithread design pattern
Multithread design pattern
 

Viewers also liked

java 8 람다식 소개와 의미 고찰
java 8 람다식 소개와 의미 고찰java 8 람다식 소개와 의미 고찰
java 8 람다식 소개와 의미 고찰Sungchul Park
 
Bitcoin 2.0(blockchain technology 2)
Bitcoin 2.0(blockchain technology 2)Bitcoin 2.0(blockchain technology 2)
Bitcoin 2.0(blockchain technology 2)Wooseung Kim
 
Tdd live spring camp 2013
Tdd live spring camp 2013Tdd live spring camp 2013
Tdd live spring camp 2013beom kyun choi
 
간단 Ip 필터 구현 이야기
간단 Ip 필터 구현 이야기간단 Ip 필터 구현 이야기
간단 Ip 필터 구현 이야기beom kyun choi
 
자바8 람다식 소개
자바8 람다식 소개자바8 람다식 소개
자바8 람다식 소개beom kyun choi
 
TDD 발담그기 @ 공감세미나
TDD 발담그기 @ 공감세미나TDD 발담그기 @ 공감세미나
TDD 발담그기 @ 공감세미나beom kyun choi
 
자바8 스트림 API 소개
자바8 스트림 API 소개자바8 스트림 API 소개
자바8 스트림 API 소개beom kyun choi
 
Okjsp 13주년 발표자료: 생존 프로그래밍 Test
Okjsp 13주년 발표자료: 생존 프로그래밍 TestOkjsp 13주년 발표자료: 생존 프로그래밍 Test
Okjsp 13주년 발표자료: 생존 프로그래밍 Testbeom kyun choi
 
Aws summit 2017 사내전파교육
Aws summit 2017 사내전파교육Aws summit 2017 사내전파교육
Aws summit 2017 사내전파교육Byeongsu Kang
 
멸종하는 공룡이 되지 않으려면
멸종하는 공룡이 되지 않으려면멸종하는 공룡이 되지 않으려면
멸종하는 공룡이 되지 않으려면Byeongsu Kang
 
알고리즘 문제해결전략 #1
알고리즘 문제해결전략 #1알고리즘 문제해결전략 #1
알고리즘 문제해결전략 #1Byeongsu Kang
 
Exception log practical_coding_guide, 예외와 로그 코딩 실용 가이드
Exception log practical_coding_guide, 예외와 로그 코딩 실용 가이드Exception log practical_coding_guide, 예외와 로그 코딩 실용 가이드
Exception log practical_coding_guide, 예외와 로그 코딩 실용 가이드도형 임
 
코딩소림사 Rx java
코딩소림사 Rx java코딩소림사 Rx java
코딩소림사 Rx javaByeongsu Kang
 
예외처리가이드
예외처리가이드예외처리가이드
예외처리가이드도형 임
 
U2 product For Wiseeco
U2 product For WiseecoU2 product For Wiseeco
U2 product For Wiseeco호진 하
 
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...Igalia
 
Global mobile market report
Global mobile market reportGlobal mobile market report
Global mobile market reportChang Kim
 
Pure Function and Honest Design
Pure Function and Honest DesignPure Function and Honest Design
Pure Function and Honest DesignHyungho Ko
 
Docker 로 Linux 없이 Linux 환경에서 개발하기
Docker 로 Linux 없이 Linux 환경에서 개발하기Docker 로 Linux 없이 Linux 환경에서 개발하기
Docker 로 Linux 없이 Linux 환경에서 개발하기iFunFactory Inc.
 

Viewers also liked (20)

java 8 람다식 소개와 의미 고찰
java 8 람다식 소개와 의미 고찰java 8 람다식 소개와 의미 고찰
java 8 람다식 소개와 의미 고찰
 
Bitcoin 2.0(blockchain technology 2)
Bitcoin 2.0(blockchain technology 2)Bitcoin 2.0(blockchain technology 2)
Bitcoin 2.0(blockchain technology 2)
 
Tdd live spring camp 2013
Tdd live spring camp 2013Tdd live spring camp 2013
Tdd live spring camp 2013
 
간단 Ip 필터 구현 이야기
간단 Ip 필터 구현 이야기간단 Ip 필터 구현 이야기
간단 Ip 필터 구현 이야기
 
자바8 람다식 소개
자바8 람다식 소개자바8 람다식 소개
자바8 람다식 소개
 
TDD 발담그기 @ 공감세미나
TDD 발담그기 @ 공감세미나TDD 발담그기 @ 공감세미나
TDD 발담그기 @ 공감세미나
 
자바8 스트림 API 소개
자바8 스트림 API 소개자바8 스트림 API 소개
자바8 스트림 API 소개
 
Okjsp 13주년 발표자료: 생존 프로그래밍 Test
Okjsp 13주년 발표자료: 생존 프로그래밍 TestOkjsp 13주년 발표자료: 생존 프로그래밍 Test
Okjsp 13주년 발표자료: 생존 프로그래밍 Test
 
Aws summit 2017 사내전파교육
Aws summit 2017 사내전파교육Aws summit 2017 사내전파교육
Aws summit 2017 사내전파교육
 
멸종하는 공룡이 되지 않으려면
멸종하는 공룡이 되지 않으려면멸종하는 공룡이 되지 않으려면
멸종하는 공룡이 되지 않으려면
 
알고리즘2
알고리즘2알고리즘2
알고리즘2
 
알고리즘 문제해결전략 #1
알고리즘 문제해결전략 #1알고리즘 문제해결전략 #1
알고리즘 문제해결전략 #1
 
Exception log practical_coding_guide, 예외와 로그 코딩 실용 가이드
Exception log practical_coding_guide, 예외와 로그 코딩 실용 가이드Exception log practical_coding_guide, 예외와 로그 코딩 실용 가이드
Exception log practical_coding_guide, 예외와 로그 코딩 실용 가이드
 
코딩소림사 Rx java
코딩소림사 Rx java코딩소림사 Rx java
코딩소림사 Rx java
 
예외처리가이드
예외처리가이드예외처리가이드
예외처리가이드
 
U2 product For Wiseeco
U2 product For WiseecoU2 product For Wiseeco
U2 product For Wiseeco
 
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
 
Global mobile market report
Global mobile market reportGlobal mobile market report
Global mobile market report
 
Pure Function and Honest Design
Pure Function and Honest DesignPure Function and Honest Design
Pure Function and Honest Design
 
Docker 로 Linux 없이 Linux 환경에서 개발하기
Docker 로 Linux 없이 Linux 환경에서 개발하기Docker 로 Linux 없이 Linux 환경에서 개발하기
Docker 로 Linux 없이 Linux 환경에서 개발하기
 

Similar to 세션4. 예제로 배우는 스마트 컨트랙트 프로그래밍

Neurogress how to guide
Neurogress how to guideNeurogress how to guide
Neurogress how to guideNeurogress
 
StoryCoin.Info 후원 메뉴얼(아티스트/팬)
StoryCoin.Info 후원 메뉴얼(아티스트/팬)StoryCoin.Info 후원 메뉴얼(아티스트/팬)
StoryCoin.Info 후원 메뉴얼(아티스트/팬)Brandon Chung
 
KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)
KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)
KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)Brandon Chung
 
KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)
KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)
KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)Brandon Chung
 
[ETHCon Korea 2019] Yun sungjun 윤성준
[ETHCon Korea 2019] Yun sungjun 윤성준[ETHCon Korea 2019] Yun sungjun 윤성준
[ETHCon Korea 2019] Yun sungjun 윤성준ethconkr
 
Core Ethereum Programming(Chapter1~Chapter2.2)
Core Ethereum Programming(Chapter1~Chapter2.2)Core Ethereum Programming(Chapter1~Chapter2.2)
Core Ethereum Programming(Chapter1~Chapter2.2)Jeongwhan Choi
 
와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용
와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용
와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용Brandon Chung
 
와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용
와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용
와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용Brandon Chung
 
Ethereum 스마트 컨트랙트 보안
Ethereum 스마트 컨트랙트 보안Ethereum 스마트 컨트랙트 보안
Ethereum 스마트 컨트랙트 보안TIMEGATE
 
[비트베리파트너스데이] 비트베리 비즈니스 솔루션 소개 자료
[비트베리파트너스데이] 비트베리 비즈니스 솔루션 소개 자료[비트베리파트너스데이] 비트베리 비즈니스 솔루션 소개 자료
[비트베리파트너스데이] 비트베리 비즈니스 솔루션 소개 자료Bitberry
 
비트코인 블록체인에 영구불변 메시지 개발 삽질기 - Google Next Extended Seoul 2018
비트코인 블록체인에 영구불변 메시지 개발 삽질기 - Google Next Extended Seoul 2018비트코인 블록체인에 영구불변 메시지 개발 삽질기 - Google Next Extended Seoul 2018
비트코인 블록체인에 영구불변 메시지 개발 삽질기 - Google Next Extended Seoul 2018Harry Oh
 
Axelar 22.04 bughunting case study
Axelar 22.04 bughunting case studyAxelar 22.04 bughunting case study
Axelar 22.04 bughunting case studyJinkyoung Kim
 
About the Blockchain_imcloud
About the Blockchain_imcloudAbout the Blockchain_imcloud
About the Blockchain_imcloudimcloud
 
비트코인으로 이해하는 블록체인 기술
비트코인으로 이해하는 블록체인 기술비트코인으로 이해하는 블록체인 기술
비트코인으로 이해하는 블록체인 기술Seong-Bok Lee
 
쉽게 풀어쓴 블록체인과 이더리움
쉽게 풀어쓴 블록체인과 이더리움쉽게 풀어쓴 블록체인과 이더리움
쉽게 풀어쓴 블록체인과 이더리움Dae Hyun Nam
 
AWS 기반 블록체인 (1부) - 블록체인 환경 구성하기 (박혜영 & 유다니엘, AWS 솔루션즈 아키텍트) :: AWS DevDay2018
AWS 기반 블록체인 (1부) - 블록체인 환경 구성하기 (박혜영 & 유다니엘, AWS 솔루션즈 아키텍트) :: AWS DevDay2018AWS 기반 블록체인 (1부) - 블록체인 환경 구성하기 (박혜영 & 유다니엘, AWS 솔루션즈 아키텍트) :: AWS DevDay2018
AWS 기반 블록체인 (1부) - 블록체인 환경 구성하기 (박혜영 & 유다니엘, AWS 솔루션즈 아키텍트) :: AWS DevDay2018Amazon Web Services Korea
 
초심자를 위한 블록체인 기초
초심자를 위한 블록체인 기초초심자를 위한 블록체인 기초
초심자를 위한 블록체인 기초So Sun Park
 
Bitcoin satoshi kor_chewers
Bitcoin satoshi kor_chewersBitcoin satoshi kor_chewers
Bitcoin satoshi kor_chewersDis Btopia
 

Similar to 세션4. 예제로 배우는 스마트 컨트랙트 프로그래밍 (20)

Neurogress how to guide
Neurogress how to guideNeurogress how to guide
Neurogress how to guide
 
StoryCoin.Info 후원 메뉴얼(아티스트/팬)
StoryCoin.Info 후원 메뉴얼(아티스트/팬)StoryCoin.Info 후원 메뉴얼(아티스트/팬)
StoryCoin.Info 후원 메뉴얼(아티스트/팬)
 
KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)
KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)
KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)
 
KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)
KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)
KPopCoin.TV 에서 아티스트의 코인 구입 메뉴얼(초보/고급용)
 
[ETHCon Korea 2019] Yun sungjun 윤성준
[ETHCon Korea 2019] Yun sungjun 윤성준[ETHCon Korea 2019] Yun sungjun 윤성준
[ETHCon Korea 2019] Yun sungjun 윤성준
 
Core Ethereum Programming(Chapter1~Chapter2.2)
Core Ethereum Programming(Chapter1~Chapter2.2)Core Ethereum Programming(Chapter1~Chapter2.2)
Core Ethereum Programming(Chapter1~Chapter2.2)
 
와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용
와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용
와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용
 
와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용
와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용
와라코인 ICO 참여 매뉴얼 - 초보자 및 전문가용
 
Ethereum 스마트 컨트랙트 보안
Ethereum 스마트 컨트랙트 보안Ethereum 스마트 컨트랙트 보안
Ethereum 스마트 컨트랙트 보안
 
[비트베리파트너스데이] 비트베리 비즈니스 솔루션 소개 자료
[비트베리파트너스데이] 비트베리 비즈니스 솔루션 소개 자료[비트베리파트너스데이] 비트베리 비즈니스 솔루션 소개 자료
[비트베리파트너스데이] 비트베리 비즈니스 솔루션 소개 자료
 
Blockchain
BlockchainBlockchain
Blockchain
 
비트코인 블록체인에 영구불변 메시지 개발 삽질기 - Google Next Extended Seoul 2018
비트코인 블록체인에 영구불변 메시지 개발 삽질기 - Google Next Extended Seoul 2018비트코인 블록체인에 영구불변 메시지 개발 삽질기 - Google Next Extended Seoul 2018
비트코인 블록체인에 영구불변 메시지 개발 삽질기 - Google Next Extended Seoul 2018
 
Axelar 22.04 bughunting case study
Axelar 22.04 bughunting case studyAxelar 22.04 bughunting case study
Axelar 22.04 bughunting case study
 
About the Blockchain_imcloud
About the Blockchain_imcloudAbout the Blockchain_imcloud
About the Blockchain_imcloud
 
비트코인으로 이해하는 블록체인 기술
비트코인으로 이해하는 블록체인 기술비트코인으로 이해하는 블록체인 기술
비트코인으로 이해하는 블록체인 기술
 
쉽게 풀어쓴 블록체인과 이더리움
쉽게 풀어쓴 블록체인과 이더리움쉽게 풀어쓴 블록체인과 이더리움
쉽게 풀어쓴 블록체인과 이더리움
 
AWS 기반 블록체인 (1부) - 블록체인 환경 구성하기 (박혜영 & 유다니엘, AWS 솔루션즈 아키텍트) :: AWS DevDay2018
AWS 기반 블록체인 (1부) - 블록체인 환경 구성하기 (박혜영 & 유다니엘, AWS 솔루션즈 아키텍트) :: AWS DevDay2018AWS 기반 블록체인 (1부) - 블록체인 환경 구성하기 (박혜영 & 유다니엘, AWS 솔루션즈 아키텍트) :: AWS DevDay2018
AWS 기반 블록체인 (1부) - 블록체인 환경 구성하기 (박혜영 & 유다니엘, AWS 솔루션즈 아키텍트) :: AWS DevDay2018
 
초심자를 위한 블록체인 기초
초심자를 위한 블록체인 기초초심자를 위한 블록체인 기초
초심자를 위한 블록체인 기초
 
Bitcoin satoshi kor_chewers
Bitcoin satoshi kor_chewersBitcoin satoshi kor_chewers
Bitcoin satoshi kor_chewers
 
D app ethereum
D app ethereumD app ethereum
D app ethereum
 

More from Jay JH Park

20170322-Postech Seminar-Gig Economy
20170322-Postech Seminar-Gig Economy20170322-Postech Seminar-Gig Economy
20170322-Postech Seminar-Gig EconomyJay JH Park
 
Hidden 서비스 소개 - 티스테이지강연(201061125 )
Hidden 서비스 소개 - 티스테이지강연(201061125 )Hidden 서비스 소개 - 티스테이지강연(201061125 )
Hidden 서비스 소개 - 티스테이지강연(201061125 )Jay JH Park
 
Hidden 서비스 소개
Hidden 서비스 소개 Hidden 서비스 소개
Hidden 서비스 소개 Jay JH Park
 
Samsung Pay, The future of Pay
Samsung Pay, The future of PaySamsung Pay, The future of Pay
Samsung Pay, The future of PayJay JH Park
 
클라우드 인프라 기반 서비스 개발 - ChatON
클라우드 인프라 기반 서비스 개발 - ChatON클라우드 인프라 기반 서비스 개발 - ChatON
클라우드 인프라 기반 서비스 개발 - ChatONJay JH Park
 
모바일 네트워크 친화적인 글로벌 메시징 서비스 - ChatON 개발
모바일 네트워크 친화적인 글로벌 메시징 서비스 - ChatON 개발 모바일 네트워크 친화적인 글로벌 메시징 서비스 - ChatON 개발
모바일 네트워크 친화적인 글로벌 메시징 서비스 - ChatON 개발 Jay JH Park
 

More from Jay JH Park (6)

20170322-Postech Seminar-Gig Economy
20170322-Postech Seminar-Gig Economy20170322-Postech Seminar-Gig Economy
20170322-Postech Seminar-Gig Economy
 
Hidden 서비스 소개 - 티스테이지강연(201061125 )
Hidden 서비스 소개 - 티스테이지강연(201061125 )Hidden 서비스 소개 - 티스테이지강연(201061125 )
Hidden 서비스 소개 - 티스테이지강연(201061125 )
 
Hidden 서비스 소개
Hidden 서비스 소개 Hidden 서비스 소개
Hidden 서비스 소개
 
Samsung Pay, The future of Pay
Samsung Pay, The future of PaySamsung Pay, The future of Pay
Samsung Pay, The future of Pay
 
클라우드 인프라 기반 서비스 개발 - ChatON
클라우드 인프라 기반 서비스 개발 - ChatON클라우드 인프라 기반 서비스 개발 - ChatON
클라우드 인프라 기반 서비스 개발 - ChatON
 
모바일 네트워크 친화적인 글로벌 메시징 서비스 - ChatON 개발
모바일 네트워크 친화적인 글로벌 메시징 서비스 - ChatON 개발 모바일 네트워크 친화적인 글로벌 메시징 서비스 - ChatON 개발
모바일 네트워크 친화적인 글로벌 메시징 서비스 - ChatON 개발
 

세션4. 예제로 배우는 스마트 컨트랙트 프로그래밍

  • 1. 예제로 배우는 스마트 컨트랙트 프로그래밍 ( 오재훈 jaehoon@nethru.co.kr ) Byzantium Megara Geth1.7 ethereum 연구회
  • 2. Lab 0. 실습 준비 ethereum 연구회
  • 3. Step 1. Mist 설치하기 1. Mist 다운로드 • https://github.com/ethereum/mist/releases • Mac 용 : mist-macosx-0-9-2.dmg • Windows 용 : mist-installer-0-9-2.exe 2. Mist 설치 하기 3. Mist 실행하기 • Mist 를 실행하면, node 를 실행하기 위한 바이너리들을 설치하기 시작한다. • 설치가 종료되면 오른쪽 화면이 나타난다. • geth 클라이언트를 다운로드 했는지 확인한다. • Mac : ~/Library/Application Support/Mist/binaries/Geth/unpacked/geth • Windows : C:Users사용자계정 AppDataRoamingMistbinariesGethunpackedgeth • Mist 를 종료한다. ethereum 연구회
  • 6. Solidity Ethereum 스마트 컨트랙을 개발할 때 가장 많이 사용되는 언어 문법은 자바 언어와 유사함 객체지향 언어 정적 타입언어 스코프 : Function Scope ( 참고 : Block Scope ) ethereum 연구회
  • 7. 256 비트 가상 머신 스택기반 머신 Turing Complete Ethereum Virtual Machine Program Counter PUSH1 0 CALLDATALOAD SLOAD NOT PUSH1 9 JUMPI STOP JUMPDEST PUSH1 32 CALLDATALOAD PUSH1 0 CALLDATALOAD SSTORE Memory ... StorageStack Call Data Log ethereum 연구회
  • 8. Halting Problem - Gas Cost Model https://docs.google.com/spreadsheets/d/1m 89CVujrQe5LAFJ8- YAUCcNK950dUzMQPMJBxRtGCqs/edit#gi d=0 ethereum 연구회
  • 9. Halting Problem - Gas Cost Model Data Location Gas 비용 Storage 32바이트당 20,000 Memory 32바이트당 1 Log 32바이트당 96 ( 바이트당 3 ) Call Data Zero 바이트 : 4 Non-zero 바이트 : 68 https://ethereum.stackexchange.com/questions/3/what-is-meant-by-the-term-gas Program Counter PUSH1 0 CALLDATALOAD SLOAD NOT PUSH1 9 JUMPI STOP JUMPDEST PUSH1 32 CALLDATALOAD PUSH1 0 CALLDATALOAD SSTORE Memory ... StorageStack Call Data Log ethereum 연구회
  • 10. Lab 1. 계정 생성 + 마이닝 ethereum 연구회
  • 11. Step 1. geth 클라이언트 실행하기 Mac $ cd ~/Documents/Ethereum/privatenet $ GETH=”~/Library/Application Support/Mist/binaries/Geth/unpacked/geth” $ “$GETH” --ipcpath test-net/geth.ipc --datadir test-data --dev Windows cmd> cd C:Users사용자계정AppDataRoamingMistbinariesGethunpacked cmd> C:Users사용자계정AppDataRoamingMistbinariesGethunpacked> geth --ipcpath test- net/test.ipc --datadir test-data --dev ethereum 연구회
  • 12. Step 2. geth console attach 새 터미널(커맨드 창)을 띄워서 geth console 을 실행한다. Mac $ cd ~/Documents/Ethereum/privatenet $ GETH=”~/Library/Application Support/Mist/binaries/Geth/unpacked/geth” $ “$GETH” attach test-net/geth.ipc Windows cmd> cd C:Users사용자계정AppDataRoamingMistbinariesGethunpacked cmd> C:Users사용자계정AppDataRoamingMistbinariesGethunpacked> cmd>geth attach //./pipe/test-net/test.ipc ethereum 연구회
  • 13. Step 3. Mist 실행 새로운 터미널에서 Mist 을 아래와 같이 실행한다. Mac $ cd ~/Documents/Ethereum/privatenet $ /Applications/Mist.app/Contents/MacOS/Mist --rpc test-net/geth.ipc Windows C:Program FilesMist>Mist --rpc //./pipe/test-net/test.ipc ethereum 연구회
  • 14. Step 4. 계정 생성 계정 생성 방법 1. Mist 에서 생성하기 2. Geth console 에서 생성하기 Geth console 에서 계정 생성하기 > eth.accounts [] > personal.newAccount() Passphrase: <Enter your password> Repeat passphrase: <Enter your password> "0xfb7198ad789c69c771f5cfb20f2d4978bd918e2c" > eth.accounts ["0xfb7198ad789c69c771f5cfb20f2d4978bd918e2c"] > ethereum 연구회
  • 15. Step 4. Mist 에서 계정 생성 확인 신규 계정이 생성되면 Mist 에 Main Account 가 표시된다. 0xfb7198ad789c69c771f5cfb20f2d4978bd918e2c ethereum 연구회
  • 16. Step 5. Mining 제어하기 Geth console 에서 마이닝 제어하기 • 마이닝 시작 : miner.start() • 마이닝 중지 : miner.stop() ethereum 연구회
  • 17. Step 5. Mining 결과확인 마이닝을 시작하면 Main 계정에 Ether 가 쌓이기 시작한다. ethereum 연구회
  • 18. Lab 2. 이더 송금하기 ethereum 연구회
  • 19. Step 1. 계정 추가하기 다른 계정으로 이더(ether)를 송금해 보자. 이더를 송금하려면 계정이 두 개 이상 필요하다. 1. 계정을 만들 때, 테스트를 쉽게 하려면 Main 계정과 같은 암호를 사용하는 것이 좋다. 2. Geth console 에서 추가로 계정을 하나 만 든다. ( 계정 생성 참조 ) 3. 생성된 계정이 Wallet 에 표시되는지 확인 한다. Wallet 에서 “계정 추가"를 클릭해서 계정을 추가 할 수도 있다. ethereum 연구회
  • 20. Step 2. 수신 계정 선택 1. 새로 추가한 계정(“Account 2”) 를 클릭한다. 2. 오른쪽 윗부분에 있는 “이 더 입금”을 클릭한다. ethereum 연구회
  • 21. Step 3. 송금하기 1. Geth console 에서 마이닝을 중지한다. ( miner.stop() ) 2. 금액에 “100” (이더) 를 입력한다. 3. “보내기”를 클릭한다. 4. “Send Transaction” 화면에서 계정의 비밀번호를 입력 한다. 5. “Send Transaction” 을 클릭한다.100 암호 입력 ethereum 연구회
  • 22. Step 4. 송금 진행 송금을 요청하면 자동으로 “지갑" 화면으로 이동한다. 1. 지갑 화면 아래쪽에 송금 요청한 트랜잭션이 표시되는 지 확인한다. 2. geth console 에서 마이닝을 시작한다. ( miner.start() ) 3. Mist 화면에서 트랜잭션에 대한 동의가 일어나는 과정 을 확인한다. ethereum 연구회
  • 23. Step 5. 송금 확인 트랜잭션이 완료되면 “승인 정보”가 표시되던 자리에 트랜잭션이 요청된 시간이 표시된다. 트랜잭션을 클릭해서 트랜잭션의 상세 정보를 확인한다. 클릭해서 상세정보 확인 트랜잭션 비용 ethereum 연구회
  • 24. Step 5. 계좌 잔액 확인 지갑 화면에서 “Account 2” 의 잔액 확인한다. Geth console 에서 mining 멈춘다. ethereum 연구회
  • 25. 트랜잭션 이더리움 트랜잭션 • EOA(External Owned Account) 가 다른 계정으로 보내는 메시지 트랜잭션에 포함되는 정보 1. 수신자(recipient) 2. 송신자(sender)를 식별할 수 있는 시그너쳐 3. 송신 금액(value) 4. 데이터 필드(선택사항) : 컨트랙에 보내는 메시지 5. Startgas : 최대로 소비할 수 있는 가스량 6. Gasprice : 수신자가 지불할 가스당 이더 트랜잭션 종류 • 송금 트랜잭션 • 컨트랙트 생성 트랜잭션 ( 수신자 주소가 0 ) ethereum 연구회
  • 26. Lab 3. Token Contract 만들기 ethereum 연구회
  • 27. Token 이더리움 에코 시스템에서 유동성있고 교환가능한 상품 - 예 : 코인, 마일리지 포인트, 금 소유 확인증 토큰 컨트랙트 • 토큰을 관리하기 위한 컨트랙트 • 발행 토큰 량, 토큰 장부(계정, 잔액) 관리, 송금, 인출 등을 지원함 2017년 10월 현재 Ethereum ERC20 토큰 수 : 10,565 https://etherscan.io/tokens 총 발행량 : 1,000 토큰 컨트랙트 계정 잔액 0xAB... 100 0xCD... 200 0xEF... 300 ethereum 연구회
  • 28. Minimum Viable Token pragma solidity ^0.4.16; contract MinimumViableToken { /* This creates an arraywith all balances */ mapping (address => uint256) public balanceOf; /* Initializes contract with initial supply tokens to the creator of the contract */ function MinimumViableToken(uint256 initialSupply) { balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens } /* Send coins */ function transfer(address _to, uint256 _value) { balanceOf[msg.sender] -= _value; // Subtract from the sender balanceOf[_to] += _value; // Add the same to the recipient } } https://gist.github.com/xbill82/9136c10da3414437a2000642d88d3b0d ethereum 연구회
  • 29. Smart Contract 구조 pragma solidity ^0.4.16; contract MinimumViableToken { /* This creates an arraywith all balances */ mapping (address => uint256) public balanceOf; /* Initializes contract with initial supply tokens to the creator of the contract */ function MinimumViableToken(uint256 initialSupply) { balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens } /* Send coins */ function transfer(address _to, uint256 _value) { balanceOf[msg.sender] -= _value; // Subtract from the sender balanceOf[_to] += _value; // Add the same to the recipient } } State Variables Constructor Functions Version Pragma ethereum 연구회
  • 30. Step 1. 컨트랙트 생성 화면으로 이동 1. 컨트랙트 버튼 클릭 2. 신규 컨트랙트 설치 버튼 클릭 ethereum 연구회
  • 31. Step 2. 소스 코드 복사 MinimumViableToken 코드를 “솔리디티 컨 트랙트 소스 코드"로 복사한다. 컨트랙트 코드 컴파일에 문제가 없으면, 오 른쪽 화면에 “컨트랙트 선택" 창이 나타난다. ethereum 연구회
  • 32. Step 3. Token 컨트랙트 설치 1. “컨트랙트 선택" 을 클릭한다. 2. “Minimum Viable Token” 선택한다. 3. Initial Supply 를 1000 으로 입력한다. 4. 화면을 아래로 스크롤해서 “설치" 클릭 한다. 1000 ethereum 연구회
  • 33. Step 4. Token 컨트랙트 생성 Sign 하기 컨트랙트 생성을 요청하면 “Create Contract” 창이 뜨고 계정의 암호를 묻는다. 1. 계정 암호를 입력한다. 2. SEND TRANSACTION 버튼 클릭한다. 계정 암호 입력 클릭 ethereum 연구회
  • 34. Step 5. 토큰 컨트랙트 트랜잭션 확인 컨트랙트를 생성하면, 지갑에 컨트랙트 생성 트랜잭션이 추가된다. 트랜잭션이 마이닝되지 않으면 트랜잭션이 승인되지 않은 상태로 있다. 1. Geth console 에서 “miner.start()” 명령 어로 miner 를 동작시킨다. 2. 트랜잭션이 동의과정을 거쳐서 승인이 되는 것을 확인한다. 3. 트랜잭션 처리가 완료된 것을 확인한 다. ethereum 연구회
  • 35. Step 5. 컨트랙트 생성 트랜잭션 확인 토큰 컨트랙 생성 트랜잭션이 완료되면 트랜잭션 상세 내용 을 살펴본다. 트랜잭션 비용 • 송금 트랜잭션 : 21,000 • 컨트랙트 생성 트랜잭션 비용 : 21,000 + α Gas Price • https://etherscan.io/chart/gasprice 트랜잭션 비용 ethereum 연구회
  • 36. 트랜잭션이 종료되면 생성된 컨트랙트를 클 릭하여 컨트랙트 상세 화면으로 이동한다. 주소를 더블 클릭한 후 복사한다. Step 6. Token 컨트랙트 확인 ethereum 연구회
  • 37. 지금 생성한 Minimum Viable Token 은 여러가지 문제를 가지고 있다. 1. 토큰 생성자에게 1000 토큰을 부여했지만, Mist 화면에 표시되지 않는다. a. 토큰 생성자가 자신이 토큰을 소유했다는 사실을 알기 어렵다. 1. 토큰을 전송하는 함수(transfer)에서 조건을 검사하지 않는다. a. 송신자가 자신이 가진 토큰보다 더 많은 토큰을 전송할 수 있다. b. 토큰 수신자가 보유한 토큰에 Overflow 가 발생하면, 토큰이 모두 사라질 수 있다. Minimum Viable Token 의 문제 ethereum 연구회
  • 38. Minimum Viable Token 은 지갑에 바로 등록되지 않기 때문 에 토큰 잔액을 확인하기 어렵다. Minimum Viable Token 의 잔액을 지갑에서 확인하려면, 토 큰을 수동으로 추가해야 한다. 1. “컨트랙트” 링크를 클릭한다. 2. 아래쪽으로 스크롤해서 “토큰 추가" 버튼을 클릭한다. 3. 토큰 컨트랙트 추가 화면에서 다음과 같이 입력한다. a. “토큰 컨트랙트 주소”에 좀전에 복사한 주소를 입력 b. 토큰이름 : First Minimum Viable Token c. 토큰심볼 : FMVTs d. 최소단위 십진 자리수 : 0 4. 확인을 클릭한다. Step 7. Token 추가하기 ethereum 연구회
  • 39. 토큰이 추가되면, Minimum Viable Token 을 생성한 계정에 토큰 잔액이 표시된다. 1. “지갑" 링크를 클릭한다. 2. 컨트랙트를 생성한 계정을 클릭한다. 3. 컨트랙트를 생성한 계정의 “First Minimum Viable Token” 잔액이 1000 FMVT 인지 확인한 다. Step 8. 보유 토큰 확인 ethereum 연구회
  • 40. Step 9. 토큰 송금하기 계정 잔액 Main Account 1,000 계정 잔액 Main Account 500 Account 2 500 ethereum 연구회
  • 41. 토큰도 이더와 마찬가지 방법으로 다른 계정에 송금할 수 있다. Main 계정에서 Account 2 로 500 FMVTs 를 송금해보자. 1. Account 2 계정을 클릭한다. 2. “이더 입금" 을 클릭한다. 3. “금액" 에 500을 입력한다. 4. “First Minimum Viable Token” 을 클릭한다. 송금이 완료되면 송금 결과확인한다. 1. Main 계정을 클릭해서 잔액을 확인한다. 2. Account 2 계정을 클릭해서 잔액을 확인한다. Step 9. 토큰 송금하기 ethereum 연구회
  • 42. 토큰 컨트랙트 함수를 불러서 토큰을 전송할 수도 있 다. Main 계정에서 “Account 2” 로 토큰을 100개 전송 해 보자. 1. “컨트랙트”를 클릭한다. 2. “Minimum Viable Token” 컨트랙트를 클릭한다. 3. “컨트랙트에 쓰기" 에서 “함수 선택"을 클릭한다. 4. “to - address” 에 “Account 2” 계정의 주소를 입 력한다. 5. “value” 에 600 을 입력한다. 6. “Execute from” 에서 “Main Account” 를 선택한 다. 7. 실행을 클릭한다. Step 10. 컨트랙트 함수 부르기 Account 2 주소 600 ethereum 연구회
  • 43. Step 9. 토큰 송금하기 계정 잔액 Main Account ? Account 2 1,100 계정 잔액 Main Account 500 Account 2 500 ethereum 연구회
  • 44. Smart Contract 구조 pragma solidity ^0.4.16; contract MinimumViableToken { /* This creates an arraywith all balances */ mapping (address => uint256) public balanceOf; /* Initializes contract with initial supply tokens to the creator of the contract */ function MinimumViableToken(uint256 initialSupply) { balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens } /* Send coins */ function transfer(address _to, uint256 _value) { balanceOf[msg.sender] -= _value; // Subtract from the sender balanceOf[_to] += _value; // Add the same to the recipient } } State Variables Constructor Functions Version Pragma ethereum 연구회
  • 45. Smart Contract 구조 항목 설명 version pragma Solidity 컴파일러 버전의 호환성을 지정한다. state variable 컨트랙트에 저장할 상태 변수들을 선언한다. constructor 컨트랙트의 생성자. 컨트랙트가 생성될 때 딱 1번 실행된다. function EOA 나 컨트랙트, 컨트랙트 내부에서 부를 수 있는 함수를 정의한다. function modifier 반복적으로 사용되는 조건을 정의하기 위해서 사용한다. Smart Contract 는 다음과 같은 부분으로 구성되어 있다. ethereum 연구회
  • 46. Version Pragma 표현 설명 <1.2.7 1.2.7 미만 <=1.2.7 1.2.7 이하 >1.2.7 1.2.7 초과 >=1.2.7 1.2.7 이상 =1.2.7 1.2.7 만 1.2.7 =1.2.7 과 동일 1.2.7 || 1.2.8 1.2.7 이나 1.2.8 >=1.2.9 <2.0.0 1.2.9 보다 크거나 같고, 2.0.0 미만 https://docs.npmjs.com/misc/semver ethereum 연구회
  • 47. State Variables 컨트랙트 내부에서 정의된 변수들 이더리움의 영구 스토리지에 저장됨 ( 키/값 구조 ) Gas 가 상대적으로 많이 소모됨 가시성 설명 public 모두가 접근할 수 있고, Getter function 이 자동으로 생성됨 ex ) string public name; internal 컨트랙트(혹은 컨트랙트를 상속하는 컨트랙트) 내부에서만 사용할 수 있음 private 컨트랙트 내부에서만 접근 가능함. 상속한 컨트랙트에서는 사용 불가 ethereum 연구회
  • 48. Types Value Types bool, int8, int16, int24, int32, …, int256 uint8, uint16, uint24, uint32,..., uint256 address 정적 배열 : bytes1 (byte), byte2, byte3, …, bytes32 동적 배열 : bytes, string enum function Reference Types 배열(array), 구조체(struct) Data location 을 지정할 수 있음 : storage 혹은 memory 데이터를 복사하는 비용이 많이 들 수 있기 때문에 어디에 저장할지 선택해야 함 http://solidity.readthedocs.io/en/develop/types.html ethereum 연구회
  • 49. Data Location 모든 complex type(array 나 struct) 은 data location 을 가지고 있다. • Data Location : memory, storage 변수 컨텍스트 기본 변경 State variable storage 불가능 Local variable storage 가능 함수 패러미터 memory 가능 함수 반환값 memory 가능 Program Counter PUSH1 0 CALLDATALOAD SLOAD NOT PUSH1 9 JUMPI STOP JUMPDEST PUSH1 32 CALLDATALOAD PUSH1 0 CALLDATALOAD SSTORE Memory ... Storage Stack Call Data Log ethereum 연구회
  • 50. Data Location Data location 에 따라 assignment 가 다르게 동작함 독립적인 복사본을 생성하는 assignment - Storage 와 메모리 사이의 assignment - State variable 을 변경하는 assignment 참조만을 복사하는 assignment - Local storage 에 대한 assignment - Memory 에 저장된 reference type 에서 memory 에 저장된 reference type 으로 assign 하면 복사본을 만들지 않는다. ethereum 연구회
  • 51. Functions Function Type 설명 View Function State 를 바꾸지 않는(상태를 Write 하지 않는) 함수는 view 로 선언할 수 있다. Pure Function State 를 읽거나 바꾸지 않는 함수를 pure 로 선언할 수 있다. Fallback Function 이름이 없는 함수. 패러미터가 없어야 하고, 반환값도 없어야 한다. 컨트랙의 함수를 불렀는데, 지정한 함수가 존재하지 않을 때 불린다. Function Modifier Python 의 decorator / Java 의 AOP 와 유사함 function name(<parameter types>) [internal|external|public|private] [pure|constant|view|payable] [returns (<return types>)] { ... } ethereum 연구회
  • 52. Functions - 상태 Write 아래의 경우 상태가 변경된다고 가정 1. state variable 에 기록하기 2. event 를 발생시키기 3. 다른 컨트랙 생성하기 4. selfdestruct 사용하기 5. call 을 통해서 Ether 보내기 6. view/pure 함수가 아닌 함수를 부르기 7. EVM 의 call 을 사용하기 8. 특정 opcode 를 포함하는 인라인 assembly 사용하기 ethereum 연구회
  • 53. Functions - 상태 Read 아래의 경우 상태가 변경된다고 가정 1. state variable 을 읽기 2. this.balance 를 접근하거나 <address>.balance 를 읽기 3. block, tx, msg 의 멤버 접근하기 ( msg.data, msg.sig 제외 ) 4. pure 로 선언되지 않은 함수를 부르기 5. 어떤 opcode 를 포함하는 인라인 어셈블리를 사용하기 ethereum 연구회
  • 54. Function Visibility Function Visibility 타입 : external, public, internal, private (생략하면 public) Visibility 설명 external EOA(External Owned Account) 에서만 부를 수 있음 데이터가 클 때 유리함 ( CallData 를 메모리로 복사하지 않기 때문) public EOA, 다른 컨트랙트, 컨트랙트 내부에서 부를 수 있음 EOA 가 public 메소드를 부르면 많은 비용이 발생함 ( CallData 를 메모리로 복사하기 때문에 ) internal 컨트랙트(혹은 컨트랙트를 상속하는 컨트랙트) 내부에서만 부를 수 있음 private 컨트랙트 안에서만 부를 수 있음 ( 상속한 컨트랙트에서는 부를 수 없음 ) ethereum 연구회
  • 55. Function Visibility EOA Contract function balanceOf() public function balanceOf1() external function balanceOf() internal function balanceOf() private Another Contract function balanceOf() public function balanceOf1() external function balanceOf() internal function balanceOf() private Parent Contract function balanceOf() public function balanceOf1() external function balanceOf() internal function balanceOf() private Transaction External Call (Message) Internal Call ethereum 연구회
  • 56. Function Modifier • 반복되는 논리를 한 곳에서 관리하기 위한 방법 • python 의 decorator • Java 의 AOP 와 유사함 • Ether 를 전송받는 함수에는 반드시 payable modifier 를 지정해야 함 modifier onlyOwner { require(msg.sender == owner); _; } function open() onlyOwner { open = true; } function close() onlyOwner { open = false; } function open() { require(msg.sender == owner); open = true;; } function close() { require(msg.sender == owner); open = false; } ethereum 연구회
  • 57. Special Variables - msg 변수 타입 설명 msg.sender account 메시지 송신자 msg.value uint 메시지와 함께 전송된 ether 양 msg.gas uint 남은 가스 msg.sig bytes4 calldata 의 첫번째 4 바이트 msg.data bytes calldata 전체 ethereum 연구회
  • 58. Lab 4. Wallet Visible Token ethereum 연구회
  • 59. Wallet Visible Token pragma solidity ^0.4.16; contract WalletVisibleToken { mapping (address => uint256) public balanceOf; event Transfer(address _from, address _to, uint _value); function WalletVisibleToken(uint256 initialSupply) { balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens } function transfer(address _to, uint256 _value) { balanceOf[msg.sender] -= _value; // Subtract from the sender balanceOf[_to] += _value; // Add the same to the recipient Transfer(msg.sender,_to,_value); } } Events ethereum 연구회
  • 60. Step 1. Wallet Visible Token 만들기 Mission : Wallet Visible Token 컨트랙트를 생성한다. ( 과정은 Minimum Viable Token 생성과 동일하다. ) • Initial Supply 는 “2000” 으로 지정 토큰 생성이 완료되면 Main 계정 토큰 잔액을 확인한다. • 토큰 이름, 토큰 심벌 등 토큰에 대한 정보를 지정하 지 않았기 때문에, undefined 로 표시된다. ethereum 연구회
  • 61. Step 2. 토큰 정보 수정 새로 생성된 토큰 정보를 수정한다. 1. “컨트랙트"를 클릭한다. 2. “주문형 토큰" 에서 “UNDEFINED ...” 인 토 큰을 클릭한다. 3. 토큰 수정 화면에서 다음과 같이 입력한다. a. 토큰 이름 : Wallet Visible Token b. 토큰 심벌 : WVTs c. 최소단위 십진수 : 0 4. 확인을 클릭해서 토큰 정보를 등록한다. ethereum 연구회
  • 62. Step 3. 토큰 송금 계정 잔액 Main Account 1,000 계정 잔액 Main Account 900 Account 2 100 Main Account 에서 Account 2 로 100 토큰을 송금하자 ethereum 연구회
  • 63. Step 4. 트랜잭션 이벤트 확인 다음과 같이 트랜잭션 이벤트를 확인한다. 1. “Wallet Visible Token” 컨트랙트를 선 택한다. 2. 화면을 아래쪽으로 스크롤해서 “계약 이벤트를 보기" 를 클릭한다. 3. 방금전에 송금할 때 발생한 Event 가 기록되었는지 확인한다. ethereum 연구회
  • 64. Step 5. Transfer 함수 실행 Wallet Visible Token 의 Transfer 함수를 이 용해서 “Account 2” 로 50 토큰을 송금해 보 자. • “이더 입금" 에서 전송한 이벤트와 Transfer 함수를 부른 이벤트가 동일 한 것을 확인할 수 있다. 확인이 끝나면, “계약 이벤트를 보기" 옵션 을 끈다. ethereum 연구회
  • 65. Events • EVM logging 기능을 이용하도록 설계된 장치 • 블록체인의 transaction log 에 패러미터와 함께 기록된다. • 컨트랙 내부에서는 접근할 수 없음 • 정의: 컨트랙트 안에서 선언 • event Transfer(address _from, address _to, uint _value); • event Transfer(address indexed _from, address indexed _to, uint _value); • 사용: 컨트랙트 함수에서 • Transfer(_from, _to, _value); Program Counter PUSH1 0 CALLDATALOAD SLOAD NOT PUSH1 9 JUMPI STOP JUMPDEST PUSH1 32 CALLDATALOAD PUSH1 0 CALLDATALOAD SSTORE Memory . . . StorageStack Call Data Log ethereum 연구회
  • 66. Events 1. 트랜잭션을 생성한 Application 에 결과값을 반환하는 용도 2. 트랜잭션을 생성한 Application 을 Trigger 하기 위해서 3. 히스토리 데이터를 저장하기 위한 용도 a.Log 영역은 Storage 영역에 비해 비용이 아주 저렴 b.Event 의 패러미터 세개까지 indexed 를 지정할 수 있음 c.indexed 패러미터를 이용해서 검색에 사용할 수 있음 ethereum 연구회
  • 67. Require & Revert pragma solidity ^0.4.16; contract UnsecureToken { mapping (address => uint256) public balanceOf; function UnsecureToken(uint256 initialSupply) { balanceOf[msg.sender] = initialSupply; } function transfer(address _to, uint256 _value) { if (balanceOf[_to] + _value < balanceOf[_to]) return; balanceOf[_to] += _value; if (balanceOf[msg.sender] < _value) return; balanceOf[msg.sender] -= _value; } } pragma solidity ^0.4.16; contract UnsecureToken { mapping (address => uint256) public balanceOf; function UnsecureToken(uint256 initialSupply) { balanceOf[msg.sender] = initialSupply; } function transfer(address _to, uint256 _value) { if (balanceOf[_to] + _value < balanceOf[_to]) return; if (balanceOf[msg.sender] < _value) return; balanceOf[_to] += _value; balanceOf[msg.sender] -= _value; } } ethereum 연구회
  • 68. Require & Revert pragma solidity ^0.4.16; contract UnsecureToken { mapping (address => uint256) public balanceOf; function UnsecureToken(uint256 initialSupply) { balanceOf[msg.sender] = initialSupply; } function transfer(address _to, uint256 _value) { if (balanceOf[_to] + _value < balanceOf[_to]) return; if (balanceOf[msg.sender] < _value) return; balanceOf[_to] += _value; balanceOf[msg.sender] -= _value; } } pragma solidity ^0.4.16; contract SecureToken { mapping (address => uint256) public balanceOf; function UnsecureToken(uint256 initialSupply) { balanceOf[msg.sender] = initialSupply; } function transfer(address _to, uint256 _value) { if (balanceOf[_to] + _value < balanceOf[_to]) revert(); balanceOf[_to] += _value; if (balanceOf[msg.sender] < _value) revert(); balanceOf[msg.sender] -= _value; } } ethereum 연구회
  • 69. Require & Revert pragma solidity ^0.4.16; contract SecureToken { mapping (address => uint256) public balanceOf; function UnsecureToken(uint256 initialSupply) { balanceOf[msg.sender] = initialSupply; } function transfer(address _to, uint256 _value) { if (balanceOf[_to] + _value < balanceOf[_to]) revert(); balanceOf[_to] += _value; if (balanceOf[msg.sender] < _value) revert(); balanceOf[msg.sender] -= _value; } } pragma solidity ^0.4.16; contract SecureToken { mapping (address => uint256) public balanceOf; function UnsecureToken(uint256 initialSupply) { balanceOf[msg.sender] = initialSupply; } function transfer(address _to, uint256 _value) { if (balanceOf[_to] + _value < balanceOf[_to]) revert(); if (balanceOf[msg.sender] < _value) revert(); balanceOf[_to] += _value; balanceOf[msg.sender] -= _value; } } ethereum 연구회
  • 70. Require & Revert pragma solidity ^0.4.16; contract SecureToken { mapping (address => uint256) public balanceOf; function UnsecureToken(uint256 initialSupply) { balanceOf[msg.sender] = initialSupply; } function transfer(address _to, uint256 _value) { require(balanceOf[msg.sender] >= _value); require(balanceOf[_to] + _value >= balanceOf[_to]); balanceOf[_to] += _value; balanceOf[msg.sender] -= _value; } } pragma solidity ^0.4.16; contract SecureToken { mapping (address => uint256) public balanceOf; function UnsecureToken(uint256 initialSupply) { balanceOf[msg.sender] = initialSupply; } function transfer(address _to, uint256 _value) { if (balanceOf[_to] + _value < balanceOf[_to]) revert(); if (balanceOf[msg.sender] < _value) revert(); balanceOf[_to] += _value; balanceOf[msg.sender] -= _value; } } ethereum 연구회
  • 71. Lab 5. Mist 호환 토큰 ethereum 연구회
  • 72. Wallet Compatible Token pragma solidity ^0.4.16; contract WalletCompatibleToken { string public constant name = "Wallet Compatible Token"; string public constant symbol = "WCTs"; uint8 public constant decimals = 18; mapping (address => uint256) public balanceOf; event Transfer(address _from, address _to, uint _value); function WalletCompatibleToken(uint256 initialSupply) { balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens } function transfer(address _to, uint256 _value) { require(balanceOf[msg.sender] >= _value); // Check if the sender has enough require(balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows balanceOf[msg.sender] -= _value; // Subtract from the sender balanceOf[_to] += _value; // Add the same to the recipient Transfer(msg.sender,_to,_value); } } ethereum 연구회
  • 73. Step 1. Wallet Compatible Token 만들기 Mission : Wallet Compatible Token 컨트랙트를 생성한다. ( 과정은 Minimum Viable Token 생성과 동일하다. ) • Initial Supply 는 “3,000,000,000,000,000,000,000” 으로 지정 토큰 생성이 완료되면 Main 계정 토큰 잔액을 확인한다. 토큰 잔액이 왜 “3 000” 밖에 되지 않을까? ethereum 연구회
  • 74. Decimals Solidity 는 부동 소수점 연산을 제공하지 않고 정수만을 사용해서 계산함 decimals 는 소수점 자리수를 정의함 사용자에게 토큰을 표시할 때 소수점 자리수를 이용해서 보여줌 Token Decimals Total Tokens 10,000 0 10,000 10,000 1 1,000.0 10,000 2 100.00 1,000,000,000,000,000,000 18 1.00000 00000 00000 000 ethereum 연구회
  • 75. Decimals Ether는 decimals 이 18이다. • 이더는 모두 wei 단위로 저장되고 관리된다. • Szabo, Finney, Ether 로 지정해도 실제로는 wei 단 위로만 기록된다. 단위 Wei wei 1 K wei 1,000 wei M wei 1,000,000 wei G wei 1,000,000,000 wei Szabo 1,000,000,000,000 wei Finney 1,000,000,000,000,000 wei Ether 1,000,000,000,000,000,000 wei ethereum 연구회
  • 76. Lab 6. Mist 호환 토큰2 ethereum 연구회
  • 77. pragma solidity ^0.4.16; contract WalletCompatibleToken { string public name; string public symbol; uint8 public decimals; mapping (address => uint256) public balanceOf; event Transfer(address _from, address _to, uint _value); function WalletCompatibleToken(string tokenName,string tokenSymbol,uint8 decimalUnits,uint256 initialSupply) { name = tokenName; symbol = tokenSymbol; decimals = decimalUnits; balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens } ... } Wallet Compatible Token ethereum 연구회
  • 78. Step 1. Wallet Compatible Token 만들기 Mission : Wallet Compatible Token 컨트랙트를 생 성한다. ( 과정은 Minimum Viable Token 생성과 동일하다. ) • Initial Supply 는 “3,000,000,000,000,000,000,000” 으로 지정 토큰 생성이 완료되면 Main 계정 토큰 잔액을 확 인한다. 토큰 잔액이 왜 “3 000” 밖에 되지 않을까? ethereum 연구회
  • 79. ERC20 Token Standard contract ERC20 { function totalSupply() constant returns (uint totalSupply); function balanceOf(address _owner) constant returns (uint balance); function transfer(address _to, uint _value) returns (bool success); function transferFrom(address _from, address _to, uint _value) returns (bool success); function approve(address _spender, uint _value) returns (bool success); function allowance(address _owner, address _spender) constant returns (uint remaining); event Transfer(address indexed _from, address indexed _to, uint _value); event Approval(address indexed _owner, address indexed _spender, uint _value); } https://theethereum.wiki/w/index.php/ERC20_Token_Standardethereum 연구회
  • 81. Crowd Fund 1980년 5월, 서울 택시운전사. “광주? 돈 워리, 돈 워리! 아이 베스트 드라이버” 택시운전사 만섭(송강호)은 외국손님을 태우고 광주에 갔다 통금 전에 돌아오면 밀린 월세를 갚을 수 있는 거금 10만원을 준다는 말에 독일기자 피터(토마스 크레취만)를 태우고 영문도 모른 채 길을 나선다. 광주 그리고 사람들. “모르겄어라, 우덜도 우덜한테 와 그라는지…” 어떻게든 택시비를 받아야 하는 만섭의 기지로 검문을 뚫고 겨우 들어선 광주. 위험하니 서울로 돌아가자는 만섭의 만류에도 피터는 대학생 재식(류준열)과 황기사(유해진)의 도움 속에 촬영을 시작한다. 그러나 상황은 점점 심각해지고 만섭은 집에 혼자 있을 딸 걱정에 점점 초조해지 는데… ethereum 연구회
  • 82. 여러분은 영화 “택시 운전사" 제작을 위한 크라우드 펀드 스마트 컨트랙트를 만들어야 합니다. 택시 운전사 를 제작하기 위해서는 최소 500 이더가 필요합니다. 요구사항 1. 모금 기간은 분단위로 지정된다. 2. EOA 가 펀드에 청약하면, 청약한 금액에 해당되는 증표(토큰)을 발행한다. 3. 청약 금액과 증표 비율은 1:1로 한다. 4. 모금 기간안에 모금 목표 금액을 달성하면 영화제작사에게 모금금액을 모두 송금한다. 5. 모금 기간이 지나도 모금 목표 금액이 달성되지 않으면 청약자들에게 청약한 금액을 모두 반환한다. CrowdFund 컨트랙트 ethereum 연구회
  • 83. Crowd Fund A B C D 계정 잔액 택시 운전사 제작사 (beneficiary) 목표금액: 500 이더 A 100 B 50 C 200 D 150 ethereum 연구회
  • 84. Crowd Fund 100 이더 A 100 토큰 계정 이더 잔액 Crowd Fund Token Contract A 에게 토큰 송 금 A 100 계정 토큰 잔액 A 100 ethereum 연구회
  • 85. 1. Main 계정에서 WalletCompatibleToken.sol 을 이용해서 Taxi Driver Fund 를 위한 토큰을 만든다. a. Name : TaxiDriver Token b. Symbol : TDs c. Decimal Units : 0 d. Initial Supply : 1000 2. Main 계정의 “TaxiDriver Token” 잔액이 1,000인지 확인한다. 3. TaxiDriver Token 의 주소를 복사해 둔다. Step 1. TaxiDriver Token 생성하기 ethereum 연구회
  • 86. Step 2. CrowdFund 컨트랙트 생성하기 CrowdFund.sol 을 이용해서 새로운 컨트랙트를 생성한다. 생 성자 패러미터는 다음과 같이 입력한다. 1. If successful send to : Main account 가 아닌 계정 2. Funding goal in ethers : 200 3. Duration in minutes : 10 4. Ether cost of each token : 1 5. Address of token used ad reward : Step1 에서 만든 컨트 랙트의 주소 ethereum 연구회
  • 87. Step 3. CrowdFund 로 송금 “Account 2” CowdFund 컨트랙트로 송금을 시도하자. 1. “컨트랙트" 를 클릭해서 컨트랙트 목록을 표시한다. 2. CrowdFund 컨트랙트를 클릭한다. 3. “이더 입금"을 클릭한다. 4. 금액에 100을 입력한다. 5. “전송" 버튼을 클릭한다. 6. 왼쪽과 같은 Send Transaction 화면이 뜨는지 확인한다. ethereum 연구회
  • 88. Step 4. CrowdFund 에 토큰 송금 EOA 에서 CrowdFund 에 송금했을 때, TaxiDriver Token 을 보상으로 제공하려면 CrowdFund 가 TaxiDriver Token 을 보유해야 한다. 보유한 토큰의 50%인 500 토큰을 CrowdFund 컨트랙트로 송금한다. 1. 컨트랙트 버튼을 클릭한다. 2. CrowdFund 컨트랙을 생성한다. 3. 이더 입금을 클릭한다. 4. “송신처" 계정을 선택한다. ( TaxiDriver Token 을 생성한 계정 ) 5. 금액에 500을 입력한다. 6. 전송을 클릭한다. ethereum 연구회
  • 89. Step 5. CrowdFund 보유 토큰 확인 아래와 같이 CrowdFund 보유 토큰을 확인한다. 1. CrowdFund 컨트랙트의 주소를 복사한다. 2. “컨트랙트" 를 클릭해서 컨트랙트 목록을 표시 한다. 3. “TaxiDriver” 컨트랙트를 클릭한다. 4. “Balance of” 에 CrowdFund 컨트랙트 주소를 복사한다. 5. 보유 잔액이 500인지 확인한다. CrowdFund 주소 잔액이 표시됨 ethereum 연구회
  • 90. Step 6. CrowdFund 청약 “Account 2” CowdFund 컨트랙트로 송금을 시도하자. 1. “컨트랙트" 를 클릭해서 컨트랙트 목록을 표시한다. 2. CrowdFund 컨트랙트를 클릭한다. 3. “이더 입금"을 클릭한다. 4. 금액에 100을 입력한다. 5. “전송" 버튼을 클릭한다. 6. Send Transaction 화면이 오류 없이 뜨는지 확인한다. 7. 암호를 입력하고 “Send Transaction” 을 클릭한다. ethereum 연구회
  • 91. Step 7. CrowdFund 청약 결과 확인 “지갑" 을 클릭한 후 “Account 2” 계정에서 다음을 확인한다. 1. “100 TDs” 가 입금되었다. 2. “100” 이더가 감소하였다. ethereum 연구회
  • 92. pragma solidity ^0.4.16; interface token { function transfer(address receiver, uint amount); } contract CrowdFund { address public beneficiary; uint public fundingGoal; uint public amountRaised; uint public deadline; uint public price; token public tokenReward; mapping(address => uint256) public balanceOf; bool fundingGoalReached = false; bool crowdsaleClosed = false; CrowdFund ethereum 연구회
  • 93. CrowdFund 컨트랙트 변수 설명 beneficiary 펀드가 모였을 때, 펀드를 받을 수신자 계정 fundingGoal 펀드 목표 금액( 이더 ) amountRaised 펀드 청약 금액 (이더) deadline 펀드 모금 기간 (초) price 이더와 토큰 교환 비율 tokenReward 토큰 컨트랙트 balanceOf 펀드 청약 장부 fundingGoalReached 펀드 목표 금액 도달 여부 crowdsaleClosed 펀드 청약 기한 종료 여부 ethereum 연구회
  • 94. CrowdFund event GoalReached(address beneficiaryAddress, uint amountRaisedValue); event FundTransfer(address backer, uint amount, bool isContribution); function CrowdFund( address ifSuccessfulSendTo, uint fundingGoalInEthers, uint durationInMinutes, uint etherCostOfEachToken, address addressOfTokenUsedAsReward ) { beneficiary = ifSuccessfulSendTo; fundingGoal = fundingGoalInEthers * 1 ether; deadline = now + durationInMinutes * 1 minutes; price = etherCostOfEachToken * 1 ether; tokenReward = token(addressOfTokenUsedAsReward); } ethereum 연구회
  • 95. function () payable { require(!crowdsaleClosed); uint amount = msg.value; balanceOf[msg.sender] += amount; amountRaised += amount; tokenReward.transfer(msg.sender, amount / price); FundTransfer(msg.sender, amount, true); } modifier afterDeadline() { if (now >= deadline) _; } function checkGoalReached() afterDeadline { if (amountRaised >= fundingGoal){ fundingGoalReached = true; GoalReached(beneficiary, amountRaised); } crowdsaleClosed = true; } CrowdFund ethereum 연구회
  • 96. CrowdFund function safeWithdrawal() afterDeadline { if (!fundingGoalReached) { uint amount = balanceOf[msg.sender]; balanceOf[msg.sender] = 0; if (amount > 0) { if (msg.sender.send(amount)) { FundTransfer(msg.sender, amount, false); } else { balanceOf[msg.sender] = amount; } } } if (fundingGoalReached && beneficiary == msg.sender) { if (beneficiary.send(amountRaised)) { FundTransfer(beneficiary, amountRaised, false); } else { fundingGoalReached = false; } } } }ethereum 연구회
  • 97. Step 8. CrowdFund 인출하기 기간이 만료되면 CrowdFund 컨트랙트의 CheckGoalReached 를 부른다. 1. “컨트랙트" 버튼을 클릭한다. 2. “함수 선택" 을 클릭한다. 3. “CheckGoalReached” 를 선택한다. 4. “실행" 을 클릭한다. ethereum 연구회
  • 98. Step 8. CrowdFund 인출하기 기간이 만료되면 CrowdFund 컨트랙트의 CheckGoalReached 를 부른다. 1. “컨트랙트" 버튼을 클릭한다. 2. “함수 선택" 을 클릭한다. 3. “SafeWithdrawal” 를 선택한다. 4. “실행" 을 클릭한다. ethereum 연구회
  • 99. Special Keywords Special Keywords Ether Units wei, finney, szabo, ether ● 1 ether == 1000 finney ● 1 finney == 1000 szabo ● 1 szabo == 1000,000,000,000 wei Time Units seconds, minutes, hours, days, weeks, years ● 1 == 1 seconds ● 1 minutes == 60 seconds ● 1 hours == 60 minutes ● 1 days == 24 hours ● 1 weeks == 7 days ● 1 years == 365 days ethereum 연구회
  • 100. Special Variables - block & transaction 변수 타입 설명 block.coinbase address 현재 블록의 마이너 주소 block.difficulty uint 현재 블록의 difficulty block.gaslimit uint 현재 블록의 gaslimit block.number uint 현재 블록 넘버 block.timestamp uint 현재 블록의 timestamp (초) block.blockhash(blockNumber) bytes32 주어진 블록의 해쉬값. 현재 블록을 포함해서 최근 256개 블록에서만 동작 변수 타입 설명 tx.gasprice uint 트랜잭션의 gas price tx.origin address 트랜잭션 송신자 ethereum 연구회
  • 101. Address 변수 및 함수 타입 설명 address.balance uint256 주소의 잔액 ( Wei 단위로 ) address.transfer(uint256 amount) 주어진 주소로 amount 만큼의 Wei 를 보낸다. 실패하면 throw address.send(uint256 amount) bool 주어진 주소로 amount 만큼의 Wei 를 보낸다. 실패하면 false 반환. 실패시 처리로직을 구현해야 함 address.call(...) bool 임의의 컨트랙에 있는 함수를 불러야할 때 사용한다. EVM 의 CALL 을 부른다. 실패하면 false 를 반환한다. - ether 값 지정 가능 : address.call.value(1 ether)(...) - gas 값 지정 가능 : address.call.gas(100000)(...) address.calldata(...) bool EVM 의 CALLCODE 를 부른다. 실패하면 false 를 반환 - gas(), value() 옵션 사용가능 address.delegatecall(...) bool EVM 의 DELEGATECALL 을 부른다. 실패하면 false 를 반환 call 과 동일하지만, 불린 함수에서 현재 컨트랙의 storage, balance 등을 사 용 다른 컨트랙에 있는 코드를 라이브러리로 사용할 때 필요함 - gas() 옵션 사용가능, value() 옵션은 사용할 수 없읍 ethereum 연구회
  • 102. Lab 8. Remix를 이용한 Debugging ethereum 연구회
  • 103. Step 0. Remix IDE 열기 Remix IDE 를 이용해서 스마트 컨 트랙을 개발하고 설치할 수도 있다 . 1. Mist 메뉴 창에서 “개발"을 클릭 2. “Remix IDE 열기" 메뉴 클릭 ethereum 연구회
  • 104. Remix IDE 는 파일탐색기, 편집기 , 터미널, 탭 판넬로 구성된다. Step 0. Remix IDE 창 구조 터미널 (Terminal) 편집기 (Editor) (파일탐색기 File Explorer) 탭 판넬(Tabs Panel) https://remix.readthedocs.io/en/latest/ ethereum 연구회
  • 105. Step 1. 기존 컨트랙트 실행하기 Remix IDE 에서 기존 컨트랙트를 사용할 수 있다. 1. 탭 판넬에서 Run 탭을 클릭한다. 2. Environment 에서 Injected Web3 를 선택 한다. 3. Mist 메인화면에서 “First Minimum Viable Token” 컨트랙트의 주소를복사한다. 4. At Address 에 “First Minimum Viable Token” 컨트랙트의 주소를입력한다. 5. “At Address” 를 클릭한다. 6. balanceOf 에 Main 계정 주소를 입력한다. 7. balanceOf 를 클릭해서 계정의 잔액을 확인 한다. 컨트랙트 주 소 Main 계정 주 소 ethereum 연구회
  • 106. Step 2. 디버그 하기 디버그 버튼을 누른다. ethereum 연구회
  • 107. Lab 9. Remix 스마트 컨트랙트생성 ethereum 연구회
  • 108. Step 1. 컨트랙트 파일 생성 다음 과정을 이용해서 컨트랙트 파일을 생성한다. 1. 파일탐색기 왼쪽 위에 있는 “파일 생성" 버튼을 클릭한다. 2. File Name 에 “MinimumViableToken.sol” 을 입 력한다. ethereum 연구회
  • 109. Step 2. 컨트랙트 입력 다음 과정을 이용해서 컨트랙트 파일을 생성한다. 1. 편집창에 Minimum Viable Token 소스를 복사한다. 2. Compile 탭에서 컴파일 과정에서 경고가 나오는지 확인한다. 3. 함수의 Visibility 를 명시하지 않 았기 때문에 issue 가 발생한다. 4. 함수 이름 뒤에 visibility 지정자로 public 을 입력한다. ethereum 연구회
  • 110. Step 3. 컨트랙트 생성하기 Run 탭에서 다음과 같이 컨트랙트를 신 규로 생성한다. 1. Run 탭을 클릭한다. 2. Create 창 옆에 initialSupply 를 10000 으로 입력한다. 3. Create 버튼을 클릭한다. 4. balancOf 창에 Main 계정을 입력 한다. ( 계정 입력시 : "22eb0718c892e4ca9aed56811b 4ca8ca9b8314f6” 형식) 5. balanceOf 를 클릭한다. ethereum 연구회
  • 111. 오늘 배운 것 ● EVM 구조 ● Gas Cost Model ● Smart Contract 구조 ● Event / Log ● Transaction vs Message ● ERC20 Compatible Token ● Smart Contract 작성하는 법 ● Remix 사용법 ethereum 연구회