-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdapp.html
More file actions
225 lines (211 loc) · 8.77 KB
/
dapp.html
File metadata and controls
225 lines (211 loc) · 8.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!DOCTYPE html>
<html>
<head>
<title>Session 4. dApp 실습 가이드</title>
<meta charset="utf-8">
<link href="https://fonts.googleapis.com/earlyaccess/nanumgothic.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/earlyaccess/nanumgothiccoding.css" rel="stylesheet">
<link href="css/Styles.css" rel="stylesheet">
</head>
<body>
<h1 id="main_title" align="center">Session 4. dApp 실습 가이드</h1>
<!--Step 1-->
<div class="steps">
<h3 class="sub_title">Step 1. 실습환경 준비</h3>
<div class="content">
<ol>
<li> Geth 구동 (프라이빗 네트워크 환경) </li>
<p>콘솔에 아래와 같은 옵션으로 Private network에 접속합니다.</p>
<table border="0px" width="800px" bgcolor="black" cellpadding="10pt">
<tr>
<td>
<p><code>~/etherstudy> geth --datadir private-data --networkid 15 --port 8080 --rpc --rpccorsdomain "*" --rpcapi "admin,db,eth,miner,net,txpool,personal,web3" console
</code></p>
<!--p><code>$ sh gethclient_private.sh</code></p-->
</td>
</tr>
</table>
<!--font size="2">$ ~/Library/Application\ Support/Mist/binaries/Geth/unpacked/geth --datadir private-data --networkid 15 --port 8080 --rpc --rpccorsdomain "*" --rpcapi "admin,db,eth,miner,net,txpool,personal,web3" console</font-->
<p>프롬프트가 깜빡이는지 확인하세요.</p>
<img src="img/geth_run.png" width="800px" border="1px"><br><br>
<li>프라이빗 네트워크 상호간 연결 확인하기</li>
<p>콘솔에 아래와 같이 입력하면 연결된 피어를 확인할 수 있습니다.</p>
<table border="0px" width="800px" bgcolor="black" cellpadding="10pt">
<tr>
<td>
<p><code> admin.peers</code></p>
</td>
</tr>
</table><br><br>
<h3 class="step_final"> 완료 조건</h3>
<p>CLI명령 admin.peers 입력 시 연결된 Peer들의 정보가 출력되는 지 확인하세요.</p>
<img src="img/admin_peers.png" width="800px" border="1px"><br><br><br>
<li>Dapp 환경설정</li>
<p>콘솔에 아래와 같이 입력하여 환경을 설정하세요.</p>
<table border="0px" width="800px" bgcolor="black" cellpadding="10pt">
<tr>
<td>
<p><code>
// 기본 설정 <br>
/$ node -v <font color="#ffdab9">// <a href="https://nodejs.org/ko/download/" target="_blank"> <font color="#ffdab9">설치링크</font></a></font><br>
/$ npm -v<br>
/$ npm install express-generator -g</font><br>
</p>
</p>
//--- git 설치가 된 경우, <br>
/$ git clone https://github.com/etherstudy/crowdfund_exercise.git <br>
</p>
//--- git 설치가 안된 경우, <br>
/$ express crowdfund_exercise<br>
/$ cd crowdfund_exercis <br>
/crowdfund_exercis $ <font color="#ffdab9">// <a href="https://github.com/etherstudy/crowdfund_exercise.git" target="_blank"> <font color="#ffdab9">Git링크</font></a>에서 Download Zip을 받아서 해당 폴더에 덮어쓴다.</font><br>
</p>
/crowdfund_exercis $ npm install<br>
/crowdfund_exercis $ npm start<br>
</code></p>
</td>
</tr>
</table><br>
[TIP] nodemon으로 웹서버 재시작없이 이용하기 <br>
/crowdfund_exercis $ npm install nodemon <br>
/crowdfund_exercis $ nodemon -x npm start
<br><br>
<h3 class="step_final"> 완료 조건</h3>
<p>브라우저로 <a href="http://127.0.0.1:3000" target="_blank">http://127.0.0.1:3000</a>에 접속하여 Express를 사용할 수 있는 지 확인하세요.</p>
</ol>
</div>
</div><br><br>
<!--Step 2-->
<div class="steps">
<h3 class="sub_title">Step 2. 크라우드 펀딩 시나리오</h3>
<div class="content">
<ol>
<img src="img/Session4_step2.png" width="800px" border="1px">
</ol>
</div>
</div><br><br>
<!--Step 3-->
<div class="steps">
<h3 class="sub_title">Step 3. Web3 / Contract 객체 생성</h3>
<div class="content">
<ol>
<li>Web3 연동 </li>
<p> <font color=blue>Dapp/eth.js</font> 파일에 아래와 같이 입력하여 Web3 모듈을 설치하고 Localhost에 Http로 연결하세요.</p>
<table border="0px" width="800px" bgcolor="black" cellpadding="10pt">
<tr>
<td>
<p><code>var Web3 = require('web3');<br>
var web3 = new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:8545"));</code></p>
</td>
</tr>
</table><br><br>
<li>Contract 연동</li>
<p>ABI와 Contract Address로 Contract를 호출하세요.</p>
<table border="0px" width="800px" bgcolor="black" cellpadding="10pt">
<tr>
<td style="word-break: break-all">
<p><code>// crowdFund Contract<br>
var walletTokenAbi = [<font color="gray">< ABI 입력 ></font>];<br>
var TokenContract = web3.eth.contract(walletTokenAbi).at(<font color="gray">< TokenAddress 입력 ></font>);<br><br>
// crowdFund Contract<br>
var crowdFundAbi = [<font color="gray">< ABI 입력 ></font>];<br>
var CrowdFundContract = web3.eth.contract(crowdFundAbi).at(<font color="gray">< CrowdFundAddress 입력 ></font>)</code></p>
</td>
</tr>
</table>
</ol>
</div>
</div><br><br>
<!--Step 4-->
<div class="steps">
<h3 class="sub_title">Step 4. Get / Set</h3>
<div class="content">
<ol>
<li>Contract Get </li>
<p><컨트랙트>.<함수명> 으로 컨트랙트의 Public 함수를 호출할 수 있습니다.</p>
<table border="0px" width="800px" bgcolor="black" cellpadding="10pt">
<tr>
<td>
<p><code>// 토큰 장부 조회 (balanceOf)<br>
exports.getTokenAmount = function (address) {<br>
return TokenContract.balanceOf(address);><br>
};</code></p>
</td>
</tr>
</table><br>
<table border="0px" width="800px" bgcolor="black" cellpadding="10pt">
<tr>
<td>
<p><code>// 펀딩 장부 조회 (balanceOf)<br>
exports.getFundAmount = function (address) {<br>
return CrowdFundContract.balanceOf(address);><br>
};</code></p>
</td>
</tr>
</table><br><br>
<li>Set(SendTransaction) <a href="https://web3js.readthedocs.io/en/1.0/web3-eth.html#sendtransaction
" target="_blank"> 매뉴얼열기</a></li>
<p></p>
<table border="0px" width="800px" bgcolor="black" cellpadding="10pt">
<tr>
<td>
<p><code>// 이더 트랜잭션 수행<br>
exports.sendTransaction =<br>
<br>
function(from,to,value,gas,callback) {<br>
<br>
web3.eth.sendTransaction({<br>
to: to,<br>
from: from,<br>
value: web3.toWei(value,'ether'),<br>
gas: 100000}, function (err, hash) {<br>
if (err) {<br>
return callback(err, '');<br>
} else {<br>
eturn callback(null, hash);<br>
}<br>
});<br>
};</code></p>
</td>
</tr>
</table><br><br>
<li> 마이닝 실행을 실행하여 송금을 완료 (강사만 진행합니다.) </li>
<p></p>
<table border="0px" width="800px" bgcolor="black" cellpadding="10pt">
<tr>
<td style="word-break: break-all">
<p><code> miner.start()</code></p>
</td>
</tr>
</table><br><br>
</ol>
</div>
</div>
<!--Step 5-->
<div class="steps">
<h3 class="sub_title">Step 5. Event watch</h3>
<div class="content">
<ol>
<p>Contract에서 event 형으로 선언한 함수가 호출되면 EVM에서 Event가 발생합니다.</p>
<p>event 형으로 선언한 함수는 전부 호출을 감지하여 이를 콜백처럼 활용할 수 있습니다.
<table border="0px" width="800px" bgcolor="black" cellpadding="10pt">
<tr>
<td>
<p><code>// 이벤트 모니터링<br>
exports.fundTransferEvent = function( callback ) {<br>
CrowdFundContract.FundTransfer().watch(function(error, res){<br>
if (error) {<br>
return callback(err, '');<br>
} else {<br>
return callback(null, res);<br>
}<br>
});<br>
};</code></p>
</td>
</tr>
</table><br><br>
</ol>
</div>
</div>
</body>
</html>