ERC-721をかぞえて / Enumerate ERC-721

ERC-721をかぞえて / Enumerate ERC-721

3383368c2bd31bbc7cc9c6043e335e09?s=128

Ryo Manzoku

August 27, 2019
Tweet

Transcript

  1. ERC-721Λ͔ͧ͑ͯ 2019-08-27 Road to Devcon 3.0 double jump.tokyoגࣜձࣾ ϦʔυΤϯδχΞ ຬ଍

  2. • Re-building the future of gaming
 with blockchain technology !!

    • 2018೥4݄ ૑ۀ • ϒϩοΫνΣʔϯήʔϜઐۀ։ൃձࣾ • ैۀһ17ਓʢۀ຿ҕୗΛؚΉʣ • ϒϩοΫνΣʔϯʹ೤ҙͷ͋ΔΤϯδχΞΛੵۃ࠾༻தͰ͢ʂ double jump.tokyoגࣜձࣾ
  3. • ຬ଍ ྄ ʢManzoku Ryoʣ • double jump.tokyo ϦʔυΤϯδχΞ •

    2018೥7݄ΑΓ Πϯϑϥઃܭӡ༻ɺαʔόαΠυ։ൃɺ SmartContract։ൃɺϒϩοΫνΣʔϯٕज़ௐࠪͳͲΛ୲౰ • աڈʹ͸ιʔγϟϧήʔϜձࣾɺEdTechΞϓϦձࣾͰΠϯϑϥ ΤϯδχΞͱͯ͠AWSΛத৺ͱͨ͠Ϋϥ΢υΠϯϑϥ͔ΒΞϓ Ϧ·ͰͷશମઃܭɺߏஙɺվળΛܦݧ ࣗݾ঺հ
  4. None
  5. • ຬ଍ ྄ ʢManzoku Ryoʣ • double jump.tokyo ϦʔυΤϯδχΞ •

    2018೥7݄ΑΓ Πϯϑϥઃܭӡ༻ɺαʔόαΠυ։ൃɺ SmartContract։ൃɺϒϩοΫνΣʔϯٕज़ௐࠪͳͲΛ୲౰ • աڈʹ͸ιʔγϟϧήʔϜձࣾɺEdTechΞϓϦձࣾͰΠϯϑϥ ΤϯδχΞͱͯ͠AWSΛத৺ͱͨ͠Ϋϥ΢υΠϯϑϥ͔ΒΞϓ Ϧ·ͰͷશମઃܭɺߏஙɺվળΛܦݧ ࣗݾ঺հ σβΠϯͷܦݧ͸ͳ͍ͷͰ
 SolidityͱWebύϑΥʔϚϯεͷ࿩Λ͠·͢ʂ
  6. • Ϣʔβʔମݧͱ͍͏ҙຯͰɺࠓ೔ʹ͓͍ͯ
 ΦϯνΣʔϯͰαʔϏε͸શͯΛ࣮૷͢Δͷ͸ෆՄೳ • Ethereum X.X ʹظ଴ʂ • “Read world”ʹαʔϏεΛఏڙ͢ΔͨΊʹ͸ɺΦϑνΣʔϯͱ

    ͷ૊Έ߹Θ͕ͤඞਢ • ʮERC-721τʔΫϯΛ਺͑Δʯͱ͍͏ྫͰ՝୊Λ঺հ • WebύϑΥʔϚϯεͷ؍఺͔ΒUX՝୊Λײͯ͡΋Β͑Ε͹ MyCryptoHeroesͷܦݧ͔Β͓࿩Ͱ͖Δ͜ͱ
  7. ࠓ೔͸ԕྀ͠ͳ͍͍ͯ͘ͱฉ͍ͯ·͢

  8. • ΋͍ͬͯͳ͍ • 1͔ͭΒ9͍ͭ࣋ͬͯΔ • 10Ҏ্͍࣋ͬͯΔ • 2Ҏ্ͷίϯτϥΫτͷτʔΫϯΛ͍࣋ͬͯΔ • 10Ҏ্ͷίϯτϥΫτͷτʔΫϯΛ͍࣋ͬͯΔ

    • ࣗ෼͕σϓϩΠͨ͠ίϯτϥΫτͷτʔΫϯΛ100ΞυϨεҎ্ ͕ॴ༗͍ͯ͠Δ ERC-721ͷτʔΫϯ࣋ͬͯ·͔͢ʁ
  9. • ΢ΥϨοτͱ͸ʁ • Metamask on Chrome • tokenPocket / GO

    Wallet ଞϞόΠϧܥ • Opera • HTC Exodus / FINNY • Dapper • ࣗ࡞ ΢ΥϨοτ͸ͳʹΛ࢖͍ͬͯ·͔͢ʁ
  10. • ஌Βͳ͍ • ΢ΥϨοτಠࣗϊʔυ • Infura.io • CloudFlare • ࣗલϊʔυ

    ͓࢖͍ͷ΢ΥϨοτ͕઀ଓ͍ͯ͠Δϊʔυ͸ʁ
  11. • MyCryptoHeroesͷ঺հ • ERC-721ͱERC-721 Enumerableʹ͍ͭͯ • ERC-721 Enumerableͷ࣮ࡍͱ՝୊Λ௨ͯ͠”Real world”ͷϒ ϩοΫνΣʔϯαʔϏεΛߟ͑Δ

    • MCH+ͷ঺հ ͓඼ॻ͖
  12. ʹ͍ͭͯ

  13. https://mch.gg/start

  14. • ήʔϜʹ͔͚ͨ࣌ؒ΋͓ۚ΋৘೤΋ɺ͋ͳͨͷࢿ࢈ͱͳΔੈք • ྺ্࢙ͷώʔϩʔΛूΊɺΞΠςϜΛ֫ಘ͠ɺότϧ͢Δ
 ϒϩοΫνΣʔϯRPGήʔϜ • ϒϩοΫνΣʔϯEthereum͓Αͼ෼ࢄετϨʔδIPFSΛར༻ • Ethereum্ͰͷDailyActiveUserɾNFTऔҾྔ/औҾ਺Ͱੈք1Ґ MyCryptoHeroesʢϚΠΫϦʣͱ͸

  15. ήʔϜը໘

  16. MyCryptoHeroesͷߏ੒ཁૉ &UIFSFVN 6TFS Ϣʔβʔ͸ECDSAॺ໊༻ͷൿີ伴ͱ ରʹͳΔΞυϨεΛॴ༗ ήʔϜࢿ࢈͸ɺEthereum্Λਖ਼ͱͯ͠؅ཧ ॴ༗৘ใ͸ɺϢʔβʔͷΞυϨεʹ͋Δ ॴ༗৘ใΛ֬ೝ ήʔϜࢿ࢈Λ༻͍ͯήʔϜͰ༡Ϳ ࢿ࢈ΛҭͯΔ

    MyCryotoHeroesͰ͸ ɾήʔϜࢿ࢈Λ࢖ͬͨ༡ͼͷఏڙ ɾETHʹΑΓήʔϜ಺௨՟Λൢച ɾ৽͍͠ήʔϜࢿ࢈ͷ෇༩ɺൢച ɾήʔϜࢿ࢈΁ΞʔτΛ෇༩
  17. • ϒϩοΫνΣʔϯͷ՝୊Ͱ͋ΔεέʔϥϏϦςΟͱUXͷղܾ ͷͨΊήʔϜͱͯ͠ͷػೳ͸ΦϑνΣʔϯͰߏங • σδλϧΞηοτʹ͸NFTʢERC-721ʣΛ࠾༻ • ήʔϜ಺௨՟ߪೖ෦෼ͱNFTؔ࿈ͷΈΦϯνΣʔϯ • NFTͷΞΠίϯ࡞ͬͨͷͰ࢖ͬͯͶʂγʔϧ΋͋ΔΑʂ MyCryptoHeroesͷΞʔΩςΫνϟ

  18. • 2018/9/21-10/1 ώʔϩʔϓϨηʔϧͷ࣮ࢪ • 2018/9/25-11/2 ότϧβͷ࣮ࢪ • Loom NetworkΛར༻ͨ͠ΦϯνΣʔϯότϧγεςϜ •

    2018/10/23 gRPC-WebͷGAΛड͚࣮ͯ૷ͷมߋ • 2018/11/30 ຊϦϦʔε MyCryptoHeroesϦϦʔε·Ͱͷมભ
  19. • EVMΛ౥ࡌͨ͠αΠυνΣʔϯٕज़Ͱ͋ΔLoom NetworkΛ࠾༻ • ΦϯνΣʔϯٕज़Λ༻͍ͳ͕Β࣮ߦແྉ&ߴ଎࣮ߦΛ࣮ݱ • ϒϩοΫνΣʔϯͰՁ஋Λ୲อ͠ͳ͕ΒήʔϜͱͯ͠ͷUXΛ֬ อͰ͖ͨɺɺ͸ͣ ότϧβ։࢝ͷߏ੒ &UIFSFVN

    6TFS
  20. • ϩδοΫͱͯ͠ΦϯνΣʔϯʢSolidityʣʹΑΔ࣮ߦ͸Մೳ • ͨͩ͠ɺॏ͗͢Δ • 1ότϧʹ͖ͭ10ඵఔ౓͔͔Γɺͦͷؒશͯͷॻ͖ࠐΈ͕ϒ ϩοΫ͞ΕΔࣄଶ • ͞Βʹৄ͍͠ઓ͍͸ҎԼͷεϥΠυʹͯ •

    https://mch.gg/hicon2018 • https://speakerdeck.com/rmanzoku/blockchain-game-in-practice ότϧβͷ݁Ռ
  21. MyCryptoHeroesͷߏ੒ཁૉ &UIFSFVN 6TFS Ϣʔβʔ͸ECDSAॺ໊༻ͷൿີ伴ͱ ରʹͳΔΞυϨεΛॴ༗ ήʔϜࢿ࢈͸ɺEthereum্Λਖ਼ͱͯ͠؅ཧ ॴ༗৘ใ͸ɺϢʔβʔͷΞυϨεʹ͋Δ ॴ༗৘ใΛ֬ೝ ήʔϜࢿ࢈Λ༻͍ͯήʔϜͰ༡Ϳ ࢿ࢈ΛҭͯΔ

    MyCryotoHeroesͰ͸ ɾήʔϜࢿ࢈Λ࢖ͬͨ༡ͼͷఏڙ ɾETHʹΑΓήʔϜ಺௨՟Λൢച ɾ৽͍͠ήʔϜࢿ࢈ͷ෇༩ɺൢച ɾήʔϜࢿ࢈΁ΞʔτΛ෇༩
  22. ERC-721ʹ͍ͭͯ

  23. • EthereumͰNFTΛ࣮ݱ͢Δݱ࣮తͳඪ४࢓༷ • ʮॴ༗৘ใʯʮৡ౉ʯʮৡ౉ݖͷҠৡʯΛنఆͨ͠Πϯλʔ ϑΣʔεΛ࣮૷͢Δඞཁ͕͋Δ • ඪ४࢓༷Ͱ͋ΔͨΊɺERC-721Λ࠾༻ͨ͠ήʔϜɺαʔϏεɺ औҾॴͰ௥Ճ։ൃແ͠Ͱར༻Ͱ͖ΔΑ͏ʹͳΔ • ERC-721Λ࣮૷ͨ͠

    = NFT ͱͳΔΘ͚Ͱ͸ͳ͍͜ͱΛ஫ҙ ERC-721ͱ͸
  24. ERC-721 Interfaces pragma solidity ^0.4.20; interface IERC721 /* is IERC165

    */ { event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId); event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId); event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved); function balanceOf(address _owner) external view returns (uint256); function ownerOf(uint256 _tokenId) external view returns (address); function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable; function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable; function transferFrom(address _from, address _to, uint256 _tokenId) external payable; function approve(address _approved, uint256 _tokenId) external payable; function setApprovalForAll(address _operator, bool _approved) external; function getApproved(uint256 _tokenId) external view returns (address); function isApprovedForAll(address _owner, address _operator) external view returns (bool); }
  25. • ownerOfؔ਺ʹΑΓ͋ΔτʔΫϯIDͷॴ༗ऀ͕Θ͔Δ • balaceOfؔ਺ʹΑΓ͋ΔΞΧ΢ϯτͷ૯ॴ༗਺͕Θ͔Δ • τʔΫϯͷॴ༗ऀ͸ଞऀʹτʔΫϯΛৡ౉Ͱ͖Δ • approveʹ͍ͭͯ͸ׂѪ • ͋ΔΞΧ΢ϯτͷॴ༗τʔΫϯIDҰཡ͸औಘͰ͖ͳ͍

    ERC-721ͷͰ͖Δ͜ͱͰ͖ͳ͍͜ͱ
  26. ࣗ෼ͷ࣋ͬͯΔΞηοτฒ΂͍ͨͰ͢ΑͶ

  27. ERC-721 Enumerable

  28. ERC-721 Enumerable Interface interface ERC721Enumerable is ERC721 { function totalSupply()

    external view returns (uint256); function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); function tokenByIndex(uint256 index) external view returns (uint256); }
  29. • ྻڍΛՄೳʹ͢ΔΦϓγϣϯ֦ு Enumerable • ownerͱindex͔ΒτʔΫϯIDΛऔಘͰ͖ΔtokenOfOwnerByIndexؔ਺ ͕͋Δ • balanceOfͰͱͬͨ਺͚ͩtokenOfOwnerByIndexΛͿΜճͤ͹Α͍ɻ • ಡΈऔΓࢹ఺

    • ҰཡΛऔಘͰ͖ΔΑ͏ʹͱStorage΁৘ใΛอଘ • ॻ͖ࠐΈࢹ఺ ERC-721 Enumerable
  30. • to infura.io ௚ྻ100ݸ • 60ඵ͘Β͍͔͔Δ • infra.io͸ΞϝϦΧʹαʔόʔ͕͋ΔͷͰɺ೔ຊ͔Βͩͱݫ͍͠ ͿΜ·Θͯ͠Έ·͠ΐ͏

  31. • infuraͷϊʔυ͸ɺւ֎ʹ͋ΔͨΊϨΠςϯγ͕େ͖͍ • ͍ΘΏΔʮޫ஗͍໰୊ʯ • await͍ͯ͠Δ͔ΒͰ͸ʁ • ͦ͏Ͱ͢Ͷɻ
 ͕ɺຊ୊͸ͦ͜Ͱ͸ͳ͘100ݸ΋ϦΫΤετΛൃߦ͢Δ͜ͱ •

    UXతͳ࿩ͩͱ΋ͪΖΜฒྻԽ͢΂͖ • ͔͠͠HTTP1.1ͷϒϥ΢β͸6ຊఔ౓͔͠ฒྻԽͰ͖ͳ͍ ΋͠100ݸͷτʔΫϯΛ͍࣋ͬͯΔਓͩͬͨΒ
  32. • ࠃ಺ʹ͋Δ๭ϊʔυαʔϏε • ଎͘ͳͬͨʂ • ͨͩ͠ɺϢʔβʔ͕࣋ͭ΢ΥϨοτͷϊʔυΛαʔϏεఏڙऀ ͕ࢦఆͰ͖·͔͢ʁ • ίϯτϩʔϧෆՄೳͳྖҬͰͷղܾࡦ͸ແҙຯ ࠃ಺ʹϊʔυ͕͋Ε͹Α͘ͳ͍ʁ

  33. ࣗ෼ͷ࣋ͬͯΔΞηοτฒ΂Δ͚ͩͰ΋ࠔ೉

  34. • WebͷύϑΥʔϚϯεվળʹ͓͍ͯɺࣗ෼ͨͪͷίϯτϩʔϧ ՄೳͳൣғͰ౒ྗΛ͢΂͖ɺࣗ෼ͨͪͷίϯτϩʔϧՄೳͳൣ ғΛ૿΍͢΂͖ • Wallet͸ɺ伴؅ཧͷ؍఺͔Βݴͬͯ΋ෆՄ৵Ͱ͋Δํ͕ྑ͍ • ૉ௚ʹಡΉͷͰ͸ͳ͘ɺϓϩΩγ΍ΩϟογϡΛಋೖ͢΂͖ • ͦ΋ͦ΋ϒϩοΫνΣʔϯͷʮঢ়ଶʯ͸Ωϟογϡͱ૬ੑ͕ྑ

    ͍ ಡΈऔΓύϑΥʔϚϯεʹ͍ͭͯ
  35. • transferͷλΠϛϯάͰɺॴ༗ҰཡΛ؅ཧ͍ͯ͠Δ • https://github.com/OpenZeppelin/openzeppelin-contracts/ commit/d1158ea68c597075a5aec4a77a9c16f061beffd3 • Storageͷߋ৽ͳͷͰ΋ͪΖΜGas͕͔͔Γ·͢ɻ ERC-721 Enumerableͷ࣮૷ //

    Mapping from owner to list of owned token IDs mapping(address => uint256[]) private _ownedTokens; // Mapping from token ID to index of the owner tokens list mapping(uint256 => uint256) private _ownedTokensIndex;
  36. Gasൺֱද ERC-721 ERC-721 Enumerable ྻڍ ☓ ˚ mint Gas 66,878

    158,461 transferFrom Gas 44,742 72,236 https://ropsten.etherscan.io/address/0x78b315eff64c865ad1d903cd771eb85f9bb2558c https://ropsten.etherscan.io/address/0x78b315eff64c865ad1d903cd771eb85f9bb2558c https://ropsten.etherscan.io/address/0xe18e82118b1a277d90beefe7ffd7421b606d0f83
  37. • ίϯτϥΫτ্ͰྻڍΛ࢖͏৔߹͸ඞਢ • transferFromΛ·ͱΊ࣮ͯߦ͢Δ • 20ݸ͘Β͍·Ͱߦ͚Δ • ID͝ͱʹuint256ΛׂΓ౰ͯͯͳʹ͔Λ؅ཧ͢Δ • 150ݸ͘Β͍·Ͱ͍͚Δ

    • ͦ΋ͦ΋uint256ͬͯͲ͏ࢥ͍·͔͢ Enumerable͸࢖͑ͳ͍ͷʁ
  38. • ࣗ਎ΛؚΉSmartContract͔Βݺ͹Ε͏ΔཁૉͷΈΛStorageʹ อଘ͢΂͖ • Smart Contract֎͔Βݺ͹Ε͏Δ΋ͷ͸Eventͱ࣮ͯ͠૷͢΂͖ • ΦϑνΣʔϯ΍αΠυνΣʔϯ • ERC-721ʹݶΒͣͦ͏͍͏ઃܭํ਑Λݟ͔͚Δ

    • ༨ܭͳཁૉ͸ɺকདྷʹ౉ΓϢʔβʔ΁༨ܭͳGasͷෛ୲Λڧ͍Δ ͜ͱʹͳΔ → Ϣʔβʔମݧ΁ͷѱӨڹ SmartContractͷઃܭํ਑
  39. • ϒϩοΫνΣʔϯ্Ͱ͢΂ͯͷॲཧ͢Δͷ͸೉͍͠ • WebύϑΥʔϚϯεͷ໰୊΍Gasͷ؍఺͔ΒϢʔβʔମݧͱ ͯ͠΋ݫ͍͠ͱݴΘ͟Δ͓͑ͳ͍ • ࢓༷Λࣄલʹߟ͑ͯɺඞཁͳΒΦϑνΣʔϯͱซ༻͢Δ • ຊ౰ʹίϯτϥΫτͰྻڍ͢Δඞཁ͸͋Δͷ͔ʁ •

    ͦΕΛೖΕΔ͜ͱʹΑͬͯશͯͷϢʔβʔ͕GasΛෛ୲͢Δ ͜ͱΛ಄ʹೖΕ͓ͯ͘ ERC-721 EnumerableΛ௨ͯ͡
  40. • ERC-721Ͱ͔ͤͬ͘ن͕ܾ֨·͍ͬͯΔͷ͔ͩΒ͍͍ײ͡ʹͰ ͖ͳ͍ͷɺɺʁ • ϒϩοΫνΣʔϯͰσδλϧΞηοτ؅ཧ͍͚ͨͩ͠ͳΜ͚ͩ Ͳɺɺɺ • ϒϩοΫνΣʔϯήʔϜͬͯͳΜ͔ͩϒϧʔΦʔγϟϯΒ͍͠ ͡Όͳ͍ʁ ͱ͜ΖͰɺɺ

  41. ʹ͍ͭͯ

  42. • ʮήʔϜʹ͔͚ͨ࣌ؒ΋͓ۚ΋৘೤΋ɺ͋ͳͨͷࢿ࢈ͱͳΔੈ քʯͷ֦େΛ໨ࢦͯ͠ • NFT͕ήʔϜͱήʔϜΛඈͼӽ͑Δੈք؍ͷ࣮ݱʹΉ͚ͯ • MyCryptoHeroesͷϊ΢ϋ΢ΛϑϨʔϜϫʔΫͱͯ͠ఏڙ͢Δϒ ϩοΫνΣʔϯήʔϜ։ൃࢧԉϓϩάϥϜ • ϒϩοΫνΣʔϯήʔϜࢢ৔΁ͷࢀೖোนΛԼ͛Δ

    MCH+ͱ͸
  43. • ΋ͪΖΜྻڍػೳ΋ఏڙ • ERC-721 Metadataػೳ • Approvalؔ࿈ • ͦͷଞӶҙ։ൃதʂ ERC-721ʹ·ͭΘΔAPIΛఏڙ༧ఆ

  44. ERC-721 Interfaces pragma solidity ^0.4.20; interface IERC721 /* is IERC165

    */ { event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId); event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId); event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved); function balanceOf(address _owner) external view returns (uint256); function ownerOf(uint256 _tokenId) external view returns (address); function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable; function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable; function transferFrom(address _from, address _to, uint256 _tokenId) external payable; function approve(address _approved, uint256 _tokenId) external payable; function setApprovalForAll(address _operator, bool _approved) external; function getApproved(uint256 _tokenId) external view returns (address); function isApprovedForAll(address _owner, address _operator) external view returns (bool); }
  45. • ERC-721ʹ͓͍ͯɺtransferΠϕϯτ͸ඞਢ • ੜ·Ε͔ͯΒશͯͷtransferΛ௥͑͹ɺݱࡏͷঢ়ଶ͸൑໌͢Δ ΦϑνΣʔϯͰؤுΔྻڍ $ curl -s https://beta-api.mch.plus/inventory/ethereum/mainnet/ 0xd868711BD9a2C6F1548F5f4737f71DA67d821090/0xdceaf1652a131F32a821468Dc03A

    92df0edd86Ea { "token_ids": [ 10021522, 10220372, 20270673, 20270688 ] }
  46. ൺֱද ERC-721 ERC-721 Enumerable MCH+ ERC-721 ྻڍ ☓ ˚ ̋

    mint Gas 66,878 158,461 66,871 transfer Gas 44,742 72,236 44,742
  47. RE-BUILDING THE FUTURE OF GAMING WITH BLOCKCHAIN TECHNOLOGY !!