Upload
jihong-shim
View
347
Download
5
Embed Size (px)
Citation preview
Đapps 개발 시연 2015-02-14 서울 이더리움 미트업 심지홍 [email protected]
Đapps : Decentralized Applications
• Front end
• HTML or QML, JavaScript, any other platform..
• Back end
• Serpent(Python), LLL(Lisp), Solidity(C++), Mutan(go) …
• Clients
• AlethZero, Mist, Pyethereum, EthereumJ
Đapp 개발 환경
• Ubuntu - VM
• AlethZero
• POC 7 - 0.7.10
• POC 8은 현재 개발중
• POC 버전에 따라 Serpent, JavaScript 등의 문법이 상이
Đapp 시연
• JH Coin
• Ethereum forum - education - tutorial 1,2 를 참고
• 발행량 1억, 튜토리얼을 기반으로 코인 지갑과 전송 기능
• 개발 순서
• Serpent로 contract 작성 후 blockchain에 전송
• JH Coin contract가 정상 작동 하는지 확인
• HTML과 JavaScript로 Front end 작성
JH Coin 소스코드 - Serpent• init() 메소드는 contract 최초 등록시에 단 한번 실행.
• code() 메소드는 contract가 호출 될 때마다 반복해서 실행.
• 유저가 contract를 호출 할 때 보내는 메시지에 다음이 포함
• msg.sender, msg.value, a function id, multiple arguments, Gas, and Gas price
• self.storage
• 각각의 contract는 자신의 저장 공간을 갖고 있음
• 32byte의 key, value 값으로 저장됨
• 이론적으로는 2^256 까지의 key로 저장가능
• msg.sender : contract에 메시지를 보낸사람의 public key
• msg.data[] : 32byte의 데이타 배열
• 메시지 전송시 [0]에는 수신자, [1]에는 전송금액을 입력
def init(): self.storage[msg.sender] = 100000000 self.storage[1] = 'JH Coin' def code(): to = msg.data[0] from = msg.sender value = msg.data[1] if self.storage[from] >= value: self.storage[from] = self.storage[from]-value self.storage[to] = self.storage[to] + value
JH Coin 소스코드 - JavaScriptvar contractAddress = ‘0x….’;
web3.eth.watch({altered: web3.eth.coinbase}).changed(function(){ web3.eth.storageAt(contractAddress).then(function(data) { web3.eth.coinbase.then(function(myAddress) { var address = myAddress; document.getElementById('coinName').innerText = web3.toAscii(data['0x01']); document.getElementById('balance').innerText = web3.toDecimal(data[address]); document.getElementById('address').innerText = address; });
}); });
function createTransaction() { var receiverAddress = '0x' + document.querySelector('#receiverAddress').value; var amount = document.querySelector('#amount').value; var data = [receiverAddress, amount]; web3.eth.transact({to: contractAddress, data: data, gas: 5000}); }
참고 사이트
• https://forum.ethereum.org/discussion/1634/tutorial-1-your-first-contract
• https://forum.ethereum.org/discussion/1635/tutorial-2-rainbow-coin
• https://forum.ethereum.org/discussion/1636/tutorial-3-introduction-to-the-javascript-api
• https://github.com/ethereum/wiki/wiki/Ethereum-Development-Tutorial