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

Crytptozombie, EOS, Trust

Hide Ogawa
October 24, 2018
370

Crytptozombie, EOS, Trust

2018年10月23日に行ったBlockchainKyotoにおけるプレゼン資料。

Cryptozombie、EOSに関してはやってみてのメモ。

Trustは信頼の形が変わりつつあり、それが近ごろのサービスの在り方、分散化の流れに深くかかわっているという話をまとめた。

Hide Ogawa

October 24, 2018
Tweet

Transcript

  1. BLOCKCHAIN KYOTO#08 CRYPTOZOMBIES, EOS, TRUST Navigate : Space / Arrow

    Keys | - Menu | - Fullscreen | - Overview | - Blackout | - Speaker | - Help M F O B S ?  1 / 56
  2. 本日のお題 1 CryptoZombie 2 EOS 3 TRUST [ GitPitch @

    github/mazarimono/block20181024 ]  2 / 56
  3. pragma solidity ^0.4.25; contract helloSolidity { function renderHelloSolidity () public

    returns (string) { return 'Hello Solidity!' } } [ GitPitch @ github/mazarimono/block20181024 ]  6 / 56
  4. internal使用例 contract Sandwitch { uint private sandwichesEaten = 0; //

    eat()という関数を作る。(internalで!) function eat() internal { sandwichesEaten++; } } // BLTはSandwitchを継承した contract BLT is Sandwitch { uint private baconSandwichesEaten = 0; function eatWithBacon() public returns (string) { baconSandwichesEaten++; // なのでeat()を使える。 eat(); [ GitPitch @ github/mazarimono/block20181024 ]  9 / 56
  5. 戻り値 function _multiply(uint a, uint b) private pure returns (uint)

    return a * b; } [ GitPitch @ github/mazarimono/block20181024 ]  11 / 56
  6. zombiesにpushされたらnewZomieというイベン トが発生する。 event NewZombie(uint zombieId, string name, uint dna) function

    _createZombie(string _name, uint _dna) private { uint id = zombies.push(Zombie(_name, _dna)) - 1; NewZombie(id, _name, _dna); } [ GitPitch @ github/mazarimono/block20181024 ]  14 / 56
  7. どんな知識??(5) データ型 ADDRESSとMAPPINGS address / 言わずと知れた Mappings / データを格納するときに使える方法の 一つ。キーバリューストア

    MSG.SENDER 全ての関数で利用できるグローバル変数の一 つ。 参考:Units(お金の単位)とグローバル変数 https://solidity.readthedocs.io/en/v0.4.25/units- and-global-variables.html [ GitPitch @ github/mazarimono/block20181024 ]  15 / 56
  8. // アカウントの残高にuintを格納する mapping (address => uint) public accountBalance; // ユーザーidを基にユーザーの名前を参照格納する場合

    mapping (uint => string) userIdToName; // 前がキー、後がバリュー。型を指定している感じ。 [ GitPitch @ github/mazarimono/block20181024 ]  16 / 56
  9. これを利用すると、関数を呼び出したユーザー のaddressを参照できる。 solidityは外部の呼び出し元から関数を実行する との決まりがある。関数を呼び出すまでコント ラクトはブロックチェーンに何もしない。 mapping (address => uint) favoriteNumber;

    function setMyNumber(uint _myNumber) public { favoriteNumber[msg.sender] = _myNumber; } function whatIsMyNumber() public view returns(uint) { return favoriteNumber[msg.sender]; } [ GitPitch @ github/mazarimono/block20181024 ]  17 / 56
  10. // とあるコントラクト contract LuckyNumber { mapping(address => uint) numbers; function

    setNum(uint_num) public { numbers[msg.sender] = _num; } function getNum(address _myAddress) public view returns (u return numbers[_myAddress] }) } // 別コントラクト contract NumberInterface { function getNum(address _myAddress) public view returns (u [ GitPitch @ github/mazarimono/block20181024 ]  21 / 56
  11. どんな知識??(9) OWNABLEコントラクト Ownable / 特別な権限を持つオーナーのみアドレス の更新ができるライブラリ。OpenZepplinのライブ ラリ。 onlyOwner / 修飾子。

    https://github.com/OpenZeppelin/openzeppelin- solidity/blob/master/contracts/ownership/Ownable.sol [ GitPitch @ github/mazarimono/block20181024 ]  23 / 56
  12. modifierで独自の修飾子を作り、関数に渡した。 引き数も設定できる。 mapping (uint => uint) public age; modifier olderThan(uint

    _age, uint _userId) { require (age[_userId] >= _age0); } function driverCar(uint _userId) public olderThan(18, _userId) } [ GitPitch @ github/mazarimono/block20181024 ]  27 / 56
  13. msg.value / コントラクトにEtherが送られた金額 を見る。 関数にpayable修飾子がなく、Etherをweb3.jsから 送ろうとする場合、その関数はトランザクショ ンを拒否する。 contract OnlineStore {

    funcion buySomething() external payable { require(msg.value == 0.001ether); transferTinh(msg.sender) } } [ GitPitch @ github/mazarimono/block20181024 ]  28 / 56
  14. this.balanceはコントラクトに存在する残高の総 量。 contract GetPaid is Ownable { function withdraw() external

    onlyOwner { owner.transfer(this.balance); } } // 多すぎる支払いを返す関数も作れる。 uint itemFee = 0.001 ether; msg.sender.transfer(msg.value - itemFee); [ GitPitch @ github/mazarimono/block20181024 ]  30 / 56
  15. 1 トークン所有者が送り先(address)、送りたいト ークン(uint256)をtransfer関数を使って送る。 2 approveを使って1と同様のことを行う。誰がト ークン受け取りを許可されたのかがmapping (uint => address)にてコントラクトに記録。さら に,

    トークンの受け手がtakeOwnership関数を呼び 出し。msg.senderが所有者からトークンの受け取 りを許可されているか確認し、承認済みの場合 は受け手にトークンを送る。 function transfer(address _to, uint256 _tokenId) public; // function approve(address _to, uint _tokenId) public; // 2 function takeOwnership(uint256 _tokenId) public; [ GitPitch @ github/mazarimono/block20181024 ]  37 / 56
  16. どんな知識??(21) コメント // 1行コメント、 /* 複数行コメント netspec ///のあとに @title 、

    @authorはそのままの意味、@noticeはユ ーザー向け、@devは開発者向けの更なる解説。 @param、 @return 関数の各@パラメーターに ついて記述。 [ GitPitch @ github/mazarimono/block20181024 ]  39 / 56