Upgrade to Pro — share decks privately, control downloads, hide ads and more …

gethoハッカソン -ハンズオン-

B0ada84fd8c179c329cc64455f11b04b?s=47 daisuke sato
December 01, 2018

gethoハッカソン -ハンズオン-

gethoハッカソンの時のハンズオンの内容です。

B0ada84fd8c179c329cc64455f11b04b?s=128

daisuke sato

December 01, 2018
Tweet

Transcript

  1. getho Hackathon ϋϯζΦϯ

  2. ࣗݾ঺հ ໊લ: ࠤ౻ େี(@st_dsk) ձࣾ: Popshoot, Inc ݴޠ: Golang, Swift,

    ೔ຊޠ, ӳޠ ࢓ࣄ: Server/Infra ΤϯδχΞ, iOS
  3. ࠓ೔࿩͢͜ͱ 1. ΠʔαϦΞϜʹ͍ͭͯ 2. εϚʔτίϯτϥΫτʹ͍ͭͯ 3. DApp։ൃπʔϧʹ͍ͭͯ 4. gethoʹ͍ͭͯ 5.

    ؆୯ͳτʔΫϯͷ࡞੒ͱσϓϩΠ 6. ToDoΞϓϦͷ঺հ
  4. ࠓ೔࿩͢͜ͱ 1. ΠʔαϦΞϜʹ͍ͭͯ 2. εϚʔτίϯτϥΫτʹ͍ͭͯ 3. DApp։ൃπʔϧʹ͍ͭͯ 4. gethoʹ͍ͭͯ 5.

    ؆୯ͳτʔΫϯͷ࡞੒ͱσϓϩΠ 6. ToDoΞϓϦͷ঺հ
  5. ΠʔαϦΞϜʹ͍ͭͯ • Ծ૝௨՟ͷҰछ(ETH) • ΞϓϦέʔγϣϯϓϥοτϑΥʔϜ • BTCͱETHͷҧ͍? • BTC͸௨՟ͱͯ͠ͷ໾ׂ͕ϝΠϯ •

    ETH͸ΞϓϦέʔγϣϯΛಈ͔͢ ͨΊͷͷ೩ྉ(Ψε)
  6. ࠓ೔࿩͢͜ͱ 1. ΠʔαϦΞϜʹ͍ͭͯ 2. εϚʔτίϯτϥΫτʹ͍ͭͯ 3. DApp։ൃπʔϧʹ͍ͭͯ 4. gethoʹ͍ͭͯ 5.

    ؆୯ͳτʔΫϯͷ࡞੒ͱσϓϩΠ 6. ToDoΞϓϦͷ঺հ
  7. εϚʔτίϯτϥΫτʹ͍ͭͯ • εϚʔτίϯτϥΫτ • ΠʔαϦΞϜͰಈ͘ΞϓϦέʔγϣϯ • ϊʔυʹঢ়ଶΛ࣋ͭ • ίϯτϥΫτΞυϨε •

    ։ൃݴޠ • Solidity, Vyper ͳͲ
  8. Solidity • Solidity • εϚʔτίϯτϥΫτΛ࣮૷͢ΔͨΊͷݴޠ • EVMίʔυʹίϯύΠϧ͞ΕΔ • JavascriptϥΠΫ

  9. Solidity pragma solidity ^0.4.24; contract SimpleStore { uint value; function

    set(uint _value) public { value = _value; } function get() public constant returns (uint) { return value; } }
  10. Solidityݴޠ࢓༷ boolean • true or false uint v = 123

    !true // => false v == 123 // => true v != 123 // => false v == 123 && true // => true v == 123 || false // => true
  11. Solidityݴޠ࢓༷ intergers • (u)int • (u)int8 ~ (u)int256 • int/uint͸(u)int256ͷΤΠϦΞε

    uint x = 3 x = x + 5 // => 8 x = x * 5 // => 40 x = x / 5 // => 8 x = x % 5 // => 3
  12. Solidityݴޠ࢓༷ address • 20byteͷ஋(ΠʔαϦΞϜΞυϨε) • address or address payable(>=0.5.0) address

    payable x = address(0x123); address myAddress = address(this); if (x.balance < 10 && myAddress.balance >= 10) x.transfer(10);
  13. Solidityݴޠ࢓༷ array uint[2] fixedArr; fixedArr[0] = 10; // [10, 0]

    arr.length; // 2 string[] arr; arr.push("apple"); // [apple] arr.push("banana"); // [apple,banana]
  14. Solidityݴޠ࢓༷ struct struct Person { address addr; string name; uint8

    age; } Person memory p = Person(address(0xabc...), "Vitalik", 24); p.age // => 24
  15. Solidityݴޠ࢓༷ mapping mapping(address => uint) public balances; balances[msg.sender] = 100;

    balances[msg.sender] // => 100;
  16. Solidityݴޠ࢓༷ forจ for(int i = 0; i < 20; i++)

    { // do something }
  17. Solidityݴޠ࢓༷ ifจ uint a = 1; uint b = 2;

    if (a == b) { // do something } else if (a != b) { // do something } else { // do something }
  18. Solidityݴޠ࢓༷ Time 1 == 1 seconds 1 minutes == 60

    seconds 1 hours == 60 minutes 1 days == 24 hours 1 weeks == 7 days
  19. Solidityݴޠ࢓༷ Block, Transaction Properties • blockhash(uint blockNumber) returns (bytes32) •

    block.gaslimit: uint • block.number: uint • block.timestamp: uint • tx.gasprice: uint
  20. Solidityݴޠ࢓༷ ͦͷଞ • msg.sender: address payable • msg.value: uint •

    now: uint
  21. Solidityݴޠ࢓༷ storageͱmemory • storage • ϒϩοΫνΣʔϯ্ʹ࢒Δ • gas͕͔͔Δ • memory

    • ϒϩοΫνΣʔϯ্ʹ࢒Βͳ͍ • gas͕͔͔Βͳ͍
  22. Solidityݴޠ࢓༷ Function function (<parameter types>) {internal|external} [pure|view|payable] [returns (<return types>)]

    • pure, view, payable • pure: storage΁ͷΞΫηεෆՄ • view: storage΁ͷࢀরͷΈՄ • payable: ETHͷૹۚ෇͖
  23. Solidityݴޠ࢓༷ Modifier • ؔ਺࣮ߦ࣌ʹ೚ҙͷॲཧΛ࣮ߦ͢Δ contract A { address owner; modifier

    onlyOwner { require(msg.sender == owner); _; } function doSomething() public onlyOwner { // do something if owner } }
  24. ࠓ೔࿩͢͜ͱ 1. ΠʔαϦΞϜʹ͍ͭͯ 2. εϚʔτίϯτϥΫτʹ͍ͭͯ 3. DApp։ൃπʔϧʹ͍ͭͯ 4. gethoʹ͍ͭͯ 5.

    ؆୯ͳτʔΫϯͷ࡞੒ͱσϓϩΠ 6. ToDoΞϓϦͷ঺հ
  25. DApp։ൃ4େπʔϧ • ݴޠ(solidity, vyper) • ϑϨʔϜϫʔΫ(truffle, emberk) • IDE(Remix, EthFiddle)

    • ςετ༻ϒϩοΫνΣʔϯωοτϫʔΫ(ganache, getho)
  26. DApp։ൃπʔϧ • web3.js • Truffle • OpenZeppelin • MetaMask

  27. DApp։ൃπʔϧ web3.js • ϊʔυʹΞΫηε͢ΔͨΊͷϥΠϒϥϦ var Web3 = require('web3'); var web3

    = new Web3(); web3.setProvider(new web3.providers.HttpProvider('http://127.0.0.1:8545')); (web3.eth.getBalance("0x...");
  28. DApp։ൃπʔϧ Truffle • εϚʔτίϯτϥΫτΛ։ൃ͢ΔͨΊͷϑϨʔϜϫʔΫ $ truffle init $ truffle compile

    $ truffle migrate
  29. DApp։ൃπʔϧ OpenZeppelin • εϚʔτίϯτϥΫτͷςϯϓϨʔτɺϥΠϒϥϦ • ERC20, ERC721, SafeMathͳͲ

  30. DApp։ൃπʔϧ MetaMask • ϒϥ΢β΢ΥϨοτ • ETH΍τʔΫϯͷ࢒ߴࢀরɺૹۚ • web3ͱ࿈ܞ΋Մೳ

  31. ࠓ೔࿩͢͜ͱ 1. ΠʔαϦΞϜʹ͍ͭͯ 2. εϚʔτίϯτϥΫτʹ͍ͭͯ 3. DApp։ൃπʔϧʹ͍ͭͯ 4. gethoʹ͍ͭͯ 5.

    ؆୯ͳτʔΫϯͷ࡞੒ͱσϓϩΠ 6. ToDoΞϓϦͷ঺հ
  32. getho DApp։ൃͷͨΊͷ։ൃϓϥοτϑΥʔϜ ಛ௃ - ςετ༻ϒϩοΫνΣʔϯωοτϫʔΫ - εϚʔτίϯτϥΫτͷ࣮ߦ؀ڥ

  33. getho Dashboard • ؆୯ʹىಈ • τϥϯβΫγϣϯཤྺ • σϑΝϧτΞΧ΢ϯτ

  34. None
  35. getho ίϯτϥΫτ࣮ߦ • GUI্Ͱ࣮ߦ • ࣮ߦ݁Ռ

  36. None
  37. ࠓ೔࿩͢͜ͱ 1. ΠʔαϦΞϜʹ͍ͭͯ 2. εϚʔτίϯτϥΫτʹ͍ͭͯ 3. DApp։ൃπʔϧʹ͍ͭͯ 4. gethoʹ͍ͭͯ 5.

    ؆୯ͳτʔΫϯͷ࡞੒ͱσϓϩΠ 6. ToDoΞϓϦͷ঺հ
  38. ؆୯ͳτʔΫϯͷ࡞੒ͱσϓϩΠ • ࡞Δ΋ͷ • ERC20τʔΫϯ • ։ൃ؀ڥ • Node •

    Truffle • OpenZeppelin • getho
  39. લ४උᶃ • gethoΞΧ΢ϯτੜ੒ • ͪ͜Β͔Β => https://getho.io

  40. લ४උᶄ • Πϯετʔϧ $ brew install node // Windows or

    Linuxͷ৔߹͸దٓ $ npm install -g truffle $ npm install -g openzeppelin-solidity
  41. લ४උᶅ • σΟϨΫτϦੜ੒ $ mkdir ~/HackathonToken $ cd ~/HackathonToken •

    truffleͷॳظԽ $ truffle init
  42. contractsʹϑΝΠϧΛ௥Ճ $ touch ./contracts/HackathonToken.sol $ vim ./contracts/HackathonToken.sol // ΤσΟλΛ։͘

  43. HackathonTokenͷ࣮૷ pragma solidity ^0.4.24; import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol"; contract HackathonToken

    is ERC20, ERC20Detailed { constructor( string name, string symbol, uint8 decimals, uint256 initialSupply ) ERC20Detailed(name, symbol, decimals) ERC20() public {} }
  44. migrationsʹϑΝΠϧΛ௥Ճ $ touch ./migrations/2_deploy_hackathon.js $ vim ./migrations/2_deploy_hackathon.js // ΤσΟλΛ։͘

  45. σϓϩΠ༻ͷmigrationίʔυΛ࣮૷ var hackathon = artifacts.require("./HackathonToken.sol"); module.exports = function(deployer){ var name

    = "Hackathon Token"; var symbol = "HKT"; var decimals = 18; var initialSupply = 1000000e18 deployer.deploy(hackathon, name, symbol, decimals, initialSupply, { }) }
  46. truffle.jsʹωοτϫʔΫͷ௥Ճ $ vim ./truffle.js // ΤσΟλΛ։͘ module.exports = { networks:

    { getho: { host: "<YOUR SUBDOMAIN>.getho.io/jsonrpc", port: 80, gas: 4712388, network_id: 1010 } } };
  47. gethoʹσϓϩΠ $ truffle migrate --network getho // => gethoͰτϥϯβΫγϣϯ֬ೝ

  48. ίϯτϥΫτΛgethoʹొ࿥ $ brew tap popshootjapan/homebrew-getho $ brew install getho //

    or go get github.com/popshootjapan/getho $ getho login $ getho upload ./build/contracts/HackathonToken.json \ -s <YOUR SUBDOMAIN> // => gethoͰίϯτϥΫτ࣮ߦ ※ getho؅ཧը໘্͔Β΋ొ࿥Ͱ͖·͢
  49. ࠓ೔࿩͢͜ͱ 1. ΠʔαϦΞϜʹ͍ͭͯ 2. εϚʔτίϯτϥΫτʹ͍ͭͯ 3. DApp։ൃπʔϧʹ͍ͭͯ 4. gethoʹ͍ͭͯ 5.

    ؆୯ͳτʔΫϯͷ࡞੒ͱσϓϩΠ 6. ToDoΞϓϦͷ঺հ
  50. ToDoΞϓϦͷ঺հ • WebΞϓϦέʔγϣϯ http://<ip>:3000/ • ιʔείʔυ https://github.com/daisuke310vvv/web3todo

  51. ϋοΧιϯΛ ָ͠Έ·͠ΐ͏ʂʂ