Ethereum ã¯ãããã¯ãã§ã¼ã³ä¸ã§ã¢ããªã±ã¼ã·ã§ã³ãåãããï¼ã¹ãã¼ãã³ã³ãã©ã¯ãï¼ã£ã¦ã®ã§èå³ãæ¹ããã¦ãã©ããªãã¨ãã§ããã®ã調ã¹ã¦ããã ãã©ãæããæ´ãããã«ä¸ã¤æ¸ãã¦ã¿ãã
ãããããã¨ã¯ãã¦ã§ããã¼ã¸ã«ééãã¿ã³ããã£ã¦ãããããç¹å®ã®ã¢ãã¬ã¹ã« Ether ãééããééã確èªããããç§å¯ã®ã³ã³ãã³ãããã¼ã¸ä¸ã«è¡¨ç¤ºãããã¦ãªãã®ãééã®ç¢ºèªã¯ã¹ãã¼ãã³ã³ãã©ã¯ãã§è¡ããããç§å¯ã®æ å ±ããããã¯ãã§ã¼ã³ä¸ã«è¨é²ããããã«ã¯ãããªãã®ã§ããã¯ã¦ã§ããµã¼ãã«ç§å¿ãããã¨ã«ãªããã¨ããã¨ãã¦ã§ããµã¼ãã«ç§ã¯ãã® Ethereum ã¢ãã¬ã¹ã§ããã¨ã»ãã¥ã¢ã«ä¼ãã¦ããå¿ è¦ããããå¾ã§æ¸ããã©ããã¾ããã解æ³ã§ã¯ãªãã
ç¥èã¼ãã®ç¶æ ããåãããªããã¨ãæ½°ãã¤ã¤ãªãã¨ãåãã¨ããã¾ã§ãããã®ã§ãã¦ã§ãã¢ããªã±ã¼ã·ã§ã³éçºè ãã¤ã¾ã¥ããã¨ãããã¡ã¢ã£ã¨ãã
- ãã¢
- MetaMask
- Web3
- æ§æ
- Truffle
- Infura
- ã¯ã¾ã£ãã¨ããã»æåããããããªãã£ãã¨ãã
- ææ
- åèæç®
ãã¢
ã¾ãã¯ãã¢ãMetaMask ã§ãRopsten ãã¹ããããã¯ã¼ã¯ã§ 0.001 ETH ééã§ããã¢ã«ã¦ã³ãã«ãã°ã¤ã³ãã¦ããå¿ è¦ããããä¸ã®ãã¿ã³ã§ Heroku ã®ãµã¤ããéãã®ã§ãããã§ï¼ä¸åº¦ãééãã¦ããªãå ´åã¯ï¼Pay ããããã©ã³ã¶ã¯ã·ã§ã³ã確å®ãã㨠Paid ã«ãªãã®ã§ãReveal ããã¨ãµã¼ãããç§å¯ã®ã³ã³ãã³ããéä¿¡ããã表示ãããã¯ãã
**********
ã½ã¼ã¹ã³ã¼ã㯠https://github.com/motemen/sketch-eth-pay-for-content ã
MetaMask
ã§ããããªã MetaMask ã£ã¦ä½ãªããã£ã¦ãªãããã ãã©ãã¦ã§ã㨠Ethererum ãããã¯ã¼ã¯ã仲ä»ãããã©ã¦ã¶æ¡å¼µãªã®ããããEthereum ã¢ã«ã¦ã³ãã®ç®¡çãããã©ã³ã¶ã¯ã·ã§ã³ã«ç½²åãã UI ãªãããæä¾ãããã¦ã§ããã¼ã¸ã¯ JavaScript çµç±ã§ MetaMask ã® API ãå¼ã³åºãã¦ãééãã³ã³ãã©ã¯ãã®å¼ã³åºãã¨ãã£ããEthereum çã«ãããå¦çããããªããã¨ãã§ããã
Mist ã¨ãããåããããªæ©è½ããã¤å°ç¨ãã©ã¦ã¶ã¿ãããªãã¤ããããã ãã©ãä¸ã«æ¸ãèªè¨¼ã®ããã® RPC ã³ã¼ã«ãå¶éããã¦ãã¦ãä»åã¯å¯¾è±¡ã¨ããªãã£ãããã®ããã«ã¾ã ã¾ã ã¤ã³ã¿ãã§ã¼ã¹ã¯æ´åããã¦ããããçºå±éä¸æãããã
Web3
ãã® JavaScript ã® API ã¨ããã®ã Web3 ã¨ããã©ã¤ãã©ãªã«ã¾ã¨ãããã¦ããï¼MetaMask ã¯ãã® web3 ã訪åãããã¼ã¸ã«åãè¾¼ãï¼ï¼ãWeb3 ã® API 㯠Ethererum ãã¼ãã¸ã® RPC å¼ã³åºãã¨ãªã£ã¦ãããgo-ethereumï¼gethï¼ã®ã³ã³ã½ã¼ã«ã Web3 ã使ãã JS ã® REPL ã¨ãã¦æä¾ããã¦ããã
ååã¯ãWeb 3.0ãã«ç±æ¥ãã¦ããã£ã½ãã
æ§æ
ããã§æ§æã®è©±ãä»åç»å ´ããã®ã¯ã²ã¨ã¤ã®ã¦ã§ãã¢ããªã±ã¼ã·ã§ã³ã¨ã²ã¨ã¤ã®ã¹ãã¼ãã³ã³ãã©ã¯ãã
- ã¹ãã¼ãã³ã³ãã©ã¯ãã¯å¥ã® Ethereum ã¢ã«ã¦ã³ããã Ether ã®éä¿¡ãåãåãããããåãåã£ãããè¨é²ãã¦ããï¼ãããã¯ãã§ã¼ã³ä¸ã«è¨é²ãããï¼ã
- ã¦ã§ãã¢ããªã±ã¼ã·ã§ã³ã¯ç§å¯ã®ã³ã³ãã³ããä¿æãã¦ããã訪åè ã®ã¢ã«ã¦ã³ããã¹ãã¼ãã³ã³ãã©ã¯ãã«éä¿¡ããé¡ããã§ãã¯ãã¦ãç§å¯ã®ã³ã³ãã³ãã訪åè ã«éä¿¡ããã
ã¹ãã¼ãã³ã³ãã©ã¯ãã®ã»ãã®ã³ã¼ãã¯ã»ã¨ãã©æããã§ããã mapping ã«éä¿¡ã¢ãã¬ã¹ã¨ãã®é¡ãä¿åããã ããåé¡ã¯ã¦ã§ãå´ã¨ãªãã
ã¦ã§ãã¢ããªã±ã¼ã·ã§ã³ã¯è¨ªåè ã® Ethereum ã¢ã«ã¦ã³ãã®ã¢ãã¬ã¹ãæ£ããç¥ãå¿ è¦ãããã訪åè ã®ã¢ãã¬ã¹ã¯ web3 çµç±ã§åå¾ãããã¨ãã§ãããããããè©ç§°ä¸å¯è½ãªå½¢ã§éåä¿¡ã§ããªãã¦ã¯ãããªãã
ããã§èããããã®ããã¯ã©ã¤ã¢ã³ããµã¤ãã§ã¡ãã»ã¼ã¸ã¸ã®ç½²åããããªãããµã¼ããµã¤ãã§ãããæ¤è¨¼ããæ¹æ³ãweb3 ã®ã¬ã¤ã¤ã§ã¯ã¾ã æ´åããã¦ããªãããMetaMask ã® RPC ã¨ãã¦ãããªã¡ã½ãããç¨æããã¦ããã
The New Secure Way To Sign Data In Your Browser – MetaMask – Medium
ããã§èª¬æããã¦ããã¡ã½ãããå¼ã³åºãã¨ä»¥ä¸ã®ãããªï¼MetaMask ã®ï¼ãã¤ã¢ãã°ã表示ãããã¦ã¼ã¶ããSignããé¸æãã㨠Ethereum ã¢ã«ã¦ã³ãã«ããã¡ãã»ã¼ã¸ã¸ã®ç½²åãçæããããããããµã¼ããåãåã£ã¦æ¤è¨¼ããã°ãã©ã®ã¢ãã¬ã¹ã®ã¢ã«ã¦ã³ããã¡ãã»ã¼ã¸ã«ç½²åããããç¥ããã¨ãã§ããã
ã¨ããããã§ãå ¨ä½ã®ããã¼ã¯ããããæãã
â¦â¦ã®ã ããã©ãç½²åããã¡ãã»ã¼ã¸ã«ã¯ã¦ã§ããµã¤ãã«ç¹æã®æ å ±ãæé»ã«ã¯å«ã¾ããªãã®ã§ãæªæãããµã¤ããã¦ã¼ã¶ã«ç½²åãããã¡ãã»ã¼ã¸ãåå©ç¨ãã¦ãã¢ã«ã¦ã³ããè©ç§°ãããã¨ãã§ãã¦ãã¾ãããã®ããä¸è¨ã®ããã«ã¦ã¼ã¶ã«ã¢ã¯ã»ã¹ãã¦ãããµã¤ãã確èªããããä¿ãã¦ãããããããã£ããè¾ãã¨ããã§ããµã¤ããªãªã¸ã³ã®æ å ±ãç½²åã«ä»ä¸ãããããã«ãªãã¨ãã¦ã§ãããã¯ã ãã¶ä½¿ãããããªãããããµã¼ãã¹ã®å©ç¨è¦ç´ã«ç½²åããããªã©ãã¡ãã»ã¼ã¸ã®å 容ãã®ãã®ã«æå³ãããå ´åã¯åé¡ã«ãªããªãã®ã ã¨æãããã®è©±ã¯ä»¥ä¸ã®ã¹ã¬ããã§ãè°è«ããã¦ããã
æ¸ãã¦ãã¨ãã«ã¯æãã¤ããªãã£ããã©ããµã¤ãã®è¨ªåè ã«ç´ä»ããããã»ãã·ã§ã³æ å ±ãå«ãã ãã©ã³ã¶ã¯ã·ã§ã³ãéä¿¡ãã¦ããããããããµã¼ããµã¤ãã§æ¤è¨¼ãããã¨ããæ¹æ³ããããããã»ãã·ã§ã³ãã¨ã«ãã©ã³ã¶ã¯ã·ã§ã³ãå¿ è¦ã ãã©ããã£ã¡ã®ã»ããææãããããªããããããã»ããããæ°ããããªâ¦â¦ã
Truffle
Truffle Suite - Your Ethereum Swiss Army Knife
éçºã®æ¹æ³ã¯è²ã ããã¿ããã ãã©ãTruffle ã使ã£ãã使ã£ã¦ã¿ãææ³ã¨ãã¦ã¯ããããããã°ååãããªãããªãSolidity ã«ããã¹ãã¼ãã³ã³ãã©ã¯ãã®éçºãJavaScript ã«ãããã¹ãããããããããã¤ã¾ã§ Truffle ãæä¾ãã¦ãã¦ããã®æ ããã¯ã¿åºãããã¨æã£ããã¨ã¯ãªãã£ããä½ã£ã¦ããã®ãå°ãããããããããªããã©ã
使ãæ¹ã¯å ¬å¼ãµã¤ãã®ãã¥ã¼ããªã¢ã«ã«è©³ããæ¸ãã¦ããã®ã§ããã¾ãè¿·ããã¨ã¯ãªãããããªããã¨æãããã¤ã°ã¬ã¼ã·ã§ã³ãã³ã³ã½ã¼ã«ã«ããã¦ã³ã³ãã©ã¯ãã表ããªãã¸ã§ã¯ããã©ãããã¤ã³ã¿ãã§ã¼ã¹ãªã®ãã¯ããããããªãã£ãã®ã§åã§æ¸ãã¦ããã©â¦â¦ã
ã¦ã§ãã¨ã®é£æº
JavaScript 㧠Ethereum ä¸ã®ã¹ãã¼ãã³ã³ãã©ã¯ãã¨ããåãããã®ã¯ web3 çµç±ã§ãã§ãããã ãã©ãtruffle-contract ã£ã¦ã¢ã¸ã¥ã¼ã«ãã¤ããã¨ãã楽ã«ãªãã
web3 ã§ã¹ãã¼ãã³ã³ãã©ã¯ãã® API ãå¼ã³åºãã«ã¯ãabi ã¨å¼ã°ããã¤ã³ã¿ãã§ã¼ã¹æ
å ±ã¨ããããã¯ã¼ã¯ä¸ã®ã¢ãã¬ã¹ã¨ããå¿
è¦ãªã®ã ãã©ãtruffle migrate
ã§ãããã¤ããã¨çæããã build/contracts/*.json
ããã®æ
å ±ããã¹ã¦ä¿æãã¦ãããããã truffle-contract ã«æ¸¡ãã°ãã¹ãã¼ãã³ã³ãã©ã¯ãã® API ã JavaScript ããé常ã«ç°¡åã«å©ããããã«ãªããç¾å¨ã® truffle-contract 3.0.4 ã§ã¯ãweb3 ã® 1.0.0-beta ã¨ã¯ç¸å®¹ããªãã®ã§æ³¨æã
ãã¹ã
ãã¹ã㯠JavaScript ã§æ¸ããããã¹ãç¨ã®ãããã¯ã¼ã¯ã«ãããã¤ããã¹ãã¼ãã³ã³ãã©ã¯ã㨠JavaScript çµç±ã§ããåãããã¤ã¡ã¼ã¸ãmocha çãªæ¸ãæ¹ãã§ãã¦ãdescribe
ã®ä»£ããã« contract
ãæ¸ããã¨ã«ãªã£ã¦ããããã¹ããæ¸ããã¨ã§ web3 ä¸ç観ãå¦ã¹ãã
Ganache
ãã¹ãç¨ã®ãã©ã¤ãã¼ããããã¯ã¼ã¯ã GUI ã§æä¾ããã¢ããªã±ã¼ã·ã§ã³ãtruffle.json 㧠development ãããã¯ã¼ã¯ãããï¼127.0.0.1:7545
ï¼ã«æå®ããã°ããã¹ããã³ã³ã½ã¼ã«ã®å®è¡æã«ãã¢ã«ã¦ã³ãããã©ã³ã¶ã¯ã·ã§ã³ã®æ§åããããããã確èªã§ãããããã©ã«ãã§ã¯èªåãã¤ãã³ã°ãæå¹ã«ãªã£ã¦ãã¦ãçºè¡ããããã©ã³ã¶ã¯ã·ã§ã³ãããã«ãããã¯ãã§ã¼ã³ã«åãè¾¼ã¾ãããããã¤ãã³ã°ã®ééãæå®ãããã¨ãã§ããéåæã«ãã©ã³ã¶ã¯ã·ã§ã³ã解決ããã¦ããä¸çã§ã®ãã¹ãã«ã便å©ã
Infura
Infura - Scalable Blockchain Infrastructure
Ethereum ãã¼ãï¼ã® RPCï¼ãæä¾ãããµã¼ããæ®éã« Ethereum ãããã¯ã¼ã¯ã¨ããã¨ããããã¨ãèããã¨ããããã¯ãã§ã¼ã³ã®ãã¹ã¦ã®ãããã¯ããã¦ã³ãã¼ãããªãã¨ãããªãããã ããInfura ãæä¾ãã RPC ã使ãã°ãã®æéãçããããã©ã³ã¶ã¯ã·ã§ã³ã¸ã®ç½²åãªã©ã¯æå ã§è¡ãã®ã§ãå®å ¨ï¼ãªã¯ãï¼ããµã¼ããµã¤ãã§ããã³ã³ãã©ã¯ãã®ãããã¤æã«ã使ã£ã¦ãããMetaMask ãããã使ã£ã¦ãããããã
ã¯ã¾ã£ãã¨ããã»æåããããããªãã£ãã¨ãã
- truffle.js 㨠truffle.conf.js ãçæãããã®ã¯ãWindows ã§
truffle
ãå®è¡ãããã¨ããã¨ãã«truffle.js
ãå¼ã³åºãããæåã®åé¿çã§ãã©ã¡ããã ãæ®ãã¦ããã°ããã - Ganache ãåèµ·åããã¨ãã§ã¼ã³ã®å
容ããªã»ãããããã®ã§ããããã¤ããã³ã³ãã©ã¯ããæ¶ãããã³ã³ãã©ã¯ãã¸ã® call ã¯ä¸è¦æåãã¦è¦ããã®ã§ã¯ã¾ã£ããããããã¦
truffle migrate --reset
ããå¿ è¦ãããã - Ropsten ãããã¯ã¼ã¯ã® gas limit 㯠truffle ããã©ã«ãã® gas limit ããä½ãã®ã§ãæ®éã«ãããã¤ãããã¨ããã¨ãexceeds block gas limitãã¨ããã¨ã©ã¼ã¡ãã»ã¼ã¸ãåºããgas ãæ示çã«æå®ãã¦ããå¿ è¦ãããã
ææ
ããã¾ã§ä¸å¤®é権çãªã¢ããªã±ã¼ã·ã§ã³ããä½ã£ããã¨ããªãã£ãã®ã§ãç°¡æãªãã®ã¨ã¯ããåççã«å é¨ç¶æ ãã¤ã¤ã¬ãã®ã¹ãã¼ãã³ã³ãã©ã¯ããæ¸ãã®ã¯çºæ³ãå¤ããªãããããªãã¨ããããã£ã¦é ã使ããã¹ãã¼ãã³ã³ãã©ã¯ãã使ãã°æ¨©éã®è¡¨ç¾ãæä½ãé©åã«ãããªããããªæ触ããã£ããé¢ç½ãã
web3 ã¯ç¾å¨ 1.0.0-beta ã®æ®µéãMetaMask ã Mist ã®è¶³ä¸¦ã¿ãæã£ã¦ããããã«ã¯æããªãã®ã§ãWeb ã¨ã®èªç¶ãªé£æºã«ã¯ããã¡ãã£ã¨æéããããããã ãã ãã© Truffle ã«ããéçºã¯æã£ã以ä¸ã«å¿«é©ã ã£ãã
åèæç®
ãããã¯ãã§ã¼ã³ã¢ããªã±ã¼ã·ã§ã³éçºã®æç§æ¸
- ä½è : å åµé·é,ç¯ åèª,丸山å¼è©©
- åºç社/ã¡ã¼ã«ã¼: ãã¤ããåºç
- çºå£²æ¥: 2018/02/01
- ã¡ãã£ã¢: åè¡æ¬ï¼ã½ããã«ãã¼ï¼
- ãã®ååãå«ãããã° (1件) ãè¦ã
ãããã¯ãã§ã¼ã³ã®æ´å²ãããã¹ãã¼ãã³ã³ãã©ã¯ãã®ã»ãã¥ãªãã£ã¾ã§åºãã«ãã¼ãã¦ãã¦ãã¨ãããããã®ä¸åãèªãã§ããã°ã ãã¶åãããæµããæ©ãåéã ã¨æããã©ãå 容ãååæ°ããã
Ethereum Pet Shop -- Your First Dapp | Truffle Suite
Truffle ã®ãã¥ã¼ããªã¢ã«ãTruffle ã«ããã¹ãã¼ãã³ã³ãã©ã¯ãã®éçºå ¨ä½ã®ãªã¼ãã¼ãã¥ã¼ãç¥ãã®ã«ããã¨æãã
geth ã§ã³ã³ãã©ã¯ãã®çæããããªãä½ã¬ã¤ã¤ãªãã¥ã¼ããªã¢ã«ããããéçºãå§ããã«ã¯ Truffle ã ãã§ãããã¨æããã©ãä¸ã§ä½ãèµ·ãã¦ããç¥ãããã£ãããããè¦ãã¨ããããã