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

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

daisuke sato
December 01, 2018

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

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

daisuke sato

December 01, 2018
Tweet

More Decks by daisuke sato

Other Decks in Technology

Transcript

  1. 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; } }
  2. Solidityݴޠ࢓༷ boolean • true or false uint v = 123

    !true // => false v == 123 // => true v != 123 // => false v == 123 && true // => true v == 123 || false // => true
  3. 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
  4. 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);
  5. Solidityݴޠ࢓༷ array uint[2] fixedArr; fixedArr[0] = 10; // [10, 0]

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

    age; } Person memory p = Person(address(0xabc...), "Vitalik", 24); p.age // => 24
  7. Solidityݴޠ࢓༷ ifจ uint a = 1; uint b = 2;

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

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

    block.gaslimit: uint • block.number: uint • block.timestamp: uint • tx.gasprice: uint
  10. Solidityݴޠ࢓༷ Function function (<parameter types>) {internal|external} [pure|view|payable] [returns (<return types>)]

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

    onlyOwner { require(msg.sender == owner); _; } function doSomething() public onlyOwner { // do something if owner } }
  12. 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...");
  13. લ४උᶄ • Πϯετʔϧ $ brew install node // Windows or

    Linuxͷ৔߹͸దٓ $ npm install -g truffle $ npm install -g openzeppelin-solidity
  14. 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 {} }
  15. σϓϩΠ༻ͷ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, { }) }
  16. truffle.jsʹωοτϫʔΫͷ௥Ճ $ vim ./truffle.js // ΤσΟλΛ։͘ module.exports = { networks:

    { getho: { host: "<YOUR SUBDOMAIN>.getho.io/jsonrpc", port: 80, gas: 4712388, network_id: 1010 } } };
  17. ίϯτϥΫτΛ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؅ཧը໘্͔Β΋ొ࿥Ͱ͖·͢