{"id":6063,"date":"2018-09-10T09:05:34","date_gmt":"2018-09-10T00:05:34","guid":{"rendered":"http:\/\/blog.jansnap.com\/?p=6063"},"modified":"2021-12-15T01:46:00","modified_gmt":"2021-12-14T16:46:00","slug":"truffle%e3%81%aepetshop%e3%83%81%e3%83%a5%e3%83%bc%e3%83%88%e3%83%aa%e3%82%a2%e3%83%ab%e3%81%ae%e8%87%aa%e5%88%86%e7%94%a8%e3%81%ae%e8%a6%81%e7%82%b9%e3%81%be%e3%81%a8%e3%82%81","status":"publish","type":"post","link":"https:\/\/blog.jansnap.com\/?p=6063","title":{"rendered":"Truffle\u306epetshop\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306e\u81ea\u5206\u7528\u306e\u8981\u70b9\u307e\u3068\u3081"},"content":{"rendered":"<p><a href=\"https:\/\/truffleframework.com\/tutorials\/pet-shop\" rel=\"nofollow noopener\" target=\"_blank\">Truffle\u306e\u30da\u30c3\u30c8\u30b7\u30e7\u30c3\u30d7\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb<\/a>\u3092\u3084\u3063\u3066\u5206\u304b\u3063\u305f\u4e8b\u306e\u30e1\u30e2\u3067\u3059\u3002<br>\n16\u5339\u306e\u30da\u30c3\u30c8\u304c\u3044\u308b\u30da\u30c3\u30c8\u30b7\u30e7\u30c3\u30d7\u3067\u3001\u305d\u308c\u305e\u308c\u8cb7\u3044\u624b\u304c\u3064\u304f\u3002\u3068\u3044\u3046\u60f3\u5b9a\u3067\u3059\u3002<br>\n\u4ed6\u306e\u65b9\u304c\u3084\u3089\u308c\u3066\u3044\u308b<a href=\"https:\/\/qiita.com\/gaisho81\/items\/06c58d5eb24ae302f690\" id=\"reference-57bee18f84522a81818f\">Truffle\u3092\u4f7f\u3063\u3066Ethereum\u3067\u30da\u30c3\u30c8\u30b7\u30e7\u30c3\u30d7\u30a2\u30d7\u30ea\u3092\u4f5c\u308b\u301c\u524d\u534a\uff1a\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u306e\u5b9f\u88c5\uff06\u30c6\u30b9\u30c8\u301c<\/a>\u304c\u53c2\u8003\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n<h2><span class=\"ez-toc-section\" id=\"%E3%82%B7%E3%82%B9%E3%83%86%E3%83%A0%E6%A6%82%E8%A6%81\"><\/span>\n\u30b7\u30b9\u30c6\u30e0\u6982\u8981<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n<ul>\n<li>\u6a5f\u80fd\u3092\u9650\u5b9a\u3057\u305f\u30da\u30c3\u30c8\u30b7\u30e7\u30c3\u30d7\u306e\u30b7\u30b9\u30c6\u30e0\u3002<\/li>\n<li>\u30da\u30c3\u30c8\u306f16\u5339\u3044\u308b\u3002<\/li>\n<li>\u30d6\u30e9\u30a6\u30b6\u3067\u30da\u30c3\u30c8\u4e00\u89a7\u304c\u898b\u308c\u3066\u3001\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u8cb7\u3048\u308b\u3002<\/li>\n<li>\u30da\u30c3\u30c8\u306e\u4ee3\u91d1\u306f\u7121\u6599\u3002<\/li>\n<li>\u8ca9\u58f2\u306e\u307f\u3067\u8cb7\u53d6\u306f\u3057\u306a\u3044\u3002<\/li>\n<li>\u98fc\u3044\u4e3b\u306e\u533a\u5225\u306f\u30a2\u30ab\u30a6\u30f3\u30c8(\u30a2\u30c9\u30ec\u30b9?)\u3067\u884c\u3046\u3002<\/li>\n<\/ul>\n\n<h2><span class=\"ez-toc-section\" id=\"%E7%92%B0%E5%A2%83%E6%A7%8B%E7%AF%89\"><\/span>\n\u74b0\u5883\u69cb\u7bc9<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n<ul>\n<li>\n<code>truffle init<\/code>\u3067\u306f\u306a\u304f\u3001<code>truffle unbox pet-shop<\/code>\u3067\u3001<a href=\"https:\/\/truffleframework.com\/boxes\" rel=\"nofollow noopener\" target=\"_blank\">Truffle Box<\/a>\u306b\u767b\u9332\u6e08\u307f\u306e\u3072\u306a\u5f62\u3092\u4f7f\u3063\u3066\u521d\u671f\u5316\u3059\u308b\u3002<\/li>\n<\/ul>\n\n<h2><span class=\"ez-toc-section\" id=\"%E3%82%B9%E3%83%9E%E3%83%BC%E3%83%88%E3%82%B3%E3%83%B3%E3%83%88%E3%83%A9%E3%82%AF%E3%83%88%E3%81%AE%E4%BD%9C%E6%88%90\"><\/span>\n\u30b9\u30de\u30fc\u30c8\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u306e\u4f5c\u6210<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n<ul>\n<li>\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u5185\u306e\u95a2\u6570\u306f2\u3064\u3060\u3051\u3002\n\n<ul>\n<li>\u98fc\u3044\u4e3b\u3092\u767b\u9332<\/li>\n<li>\u5168\u3066\u306e\u30da\u30c3\u30c8\u306e\u98fc\u3044\u4e3b\u3092\u53d6\u5f97<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n<h3><span class=\"ez-toc-section\" id=\"contract%E6%96%87\"><\/span>\ncontract\u6587<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li>contracts\/Adoption.sol\u3092\u4f5c\u6210\u3057\u3066\u3001\u4ee5\u4e0b\u3092\u8a18\u8ff0\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"text\" class=\"language-text\">pragma solidity ^0.4.17;\n\ncontract Adoption {\n\n}<\/code><\/pre>\n\n\n\n<ul>\n<li>\n<code>pragma<\/code>\u306f\u3001\u30b3\u30f3\u30d1\u30a4\u30e9\u306b\u6e21\u3059\u60c5\u5831\u3002<\/li>\n<li>\u6587\u306f\u30bb\u30df\u30b3\u30ed\u30f3<code>;<\/code>\u3067\u7d42\u308f\u308b\u3002<\/li>\n<\/ul>\n\n<h3><span class=\"ez-toc-section\" id=\"%E5%A4%89%E6%95%B0%E3%81%AE%E5%AE%A3%E8%A8%80\"><\/span>\n\u5909\u6570\u306e\u5ba3\u8a00<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li>\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u306e<code>{}<\/code>\u5185\u306b\u4ee5\u4e0b\u3092\u66f8\u3044\u3066\u5909\u6570\u5ba3\u8a00\u3002\n\n<ul>\n<li>address\u578b<\/li>\n<li>public\u306a\u306e\u3067\u3001\u5916\u90e8?\u304b\u3089\u53c2\u7167\u53ef\u3002\u81ea\u52d5\u7684\u306bgetter\u30e1\u30bd\u30c3\u30c9\u304c\u4f5c\u6210\u3055\u308c\u308b\u3002(\u306e\u3067\u3001\u5909\u6570\u540d\u305d\u306e\u307e\u307e\u3067\u547c\u3079\u3070\u4e2d\u8eab\u304c\u53d6\u5f97\u3067\u304d\u308b)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"text\" class=\"language-text\">address[16] public adopters;    \/\/ \u98fc\u3044\u4e3b\u3002address\u578b\u304c16\u500b\u306e\u914d\u5217<\/code><\/pre>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"%E9%96%A2%E6%95%B0%E3%82%92%E6%9B%B8%E3%81%8F\"><\/span>\n\u95a2\u6570\u3092\u66f8\u304f<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li>\u30da\u30c3\u30c8ID\u3092\u6574\u6570\u3067\u6e21\u3059\u3068\u3001\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u5b9f\u884c\u8005\u306eID\u3092\u914d\u5217\u5185\u306e\u8a72\u5f53\u4f4d\u7f6e\u306b\u4ee3\u5165\u3057\u3001\u30da\u30c3\u30c8ID\u3092\u8fd4\u3059\u95a2\u6570\u3002\n\n<ul>\n<li>public\u306a\u306e\u3067\u3001\u5916\u90e8\u304b\u3089\u547c\u3073\u51fa\u3057\u53ef\u80fd\u3002 <\/li>\n<li>\u5f15\u6570\u3060\u3051\u3067\u306a\u304f\u3001\u623b\u308a\u5024\u306e\u578b\u3082\u66f8\u304f\u3002<code>returns (uint)<\/code>\u306e\u90e8\u5206\u3002<\/li>\n<li>\n<code>require()<\/code>\u3067\u3001\u52d5\u4f5c\u306b\u5fc5\u8981\u306a\u6761\u4ef6\u3092\u66f8\u304f\u3002\u6761\u4ef6\u306b\u4e00\u81f4\u3057\u306a\u3051\u308c\u3070\u4f55\u3082\u305b\u305areturn\u3059\u308b\u3002<\/li>\n<li>\n<code>msg.sender<\/code>\u306b\u3001\u95a2\u6570\u3092\u547c\u3073\u51fa\u3057\u305f\u4eba\u306e\u30a2\u30c9\u30ec\u30b9\u304c\u5165\u3063\u3066\u3044\u308b\u3002\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\uff1f<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"text\" class=\"language-text\">  \/\/ Adopting a pet(\u30da\u30c3\u30c8\u3092\u8cb7\u3046)\n  function adopt(uint petId) public returns (uint) {\n    require(petId >= 0 && petId <= 15); \/\/ \u30da\u30c3\u30c8\u306f16\u5339\u306a\u306e\u3067\u3001\u7bc4\u56f2\u5916\u306epetId\u306e\u5834\u5408\u306f\u4f55\u3082\u3057\u306a\u3044\n\n    adopters[petId] = msg.sender;   \/\/ \u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u5b9f\u884c\u8005\u306e\u30a2\u30c9\u30ec\u30b9\u3092\u4ee3\u5165        \n\n    return petId;\n  }<\/code><\/pre>\n\n\n\n<ul>\n<li>\u98fc\u3044\u4e3b\u4e00\u89a7\u3092\u8fd4\u3059\u95a2\u6570\u3002\n\n<ul>\n<li>\n<code>view<\/code>\u3092\u6307\u5b9a\u3057\u3066\u3001\u8aad\u307f\u51fa\u3057\u5c02\u7528\u306e\u95a2\u6570\u306b\u3057\u3066\u3044\u308b\u3002(\u4ee5\u524d\u306f<code>constant<\/code>\u3060\u3063\u305f\u3089\u3057\u3044)<\/li>\n<li>\u623b\u308a\u5024\u306e\u578b\u306b\u3001\u914d\u5217\u306e\u9577\u3055\u307e\u3067\u66f8\u3044\u3066\u3044\u308b\u306e\u306b\u6ce8\u610f\u3002\u3000<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"text\" class=\"language-text\">  \/\/ Retrieving the adopters(\u98fc\u3044\u4e3b\u4e00\u89a7\u306e\u914d\u5217\u3092\u8fd4\u3059)\n  function getAdopters() public view returns (address[16]) {\n    return adopters;\n  }<\/code><\/pre>\n\n\n\n<h2><span class=\"ez-toc-section\" id=\"%E3%82%B3%E3%83%B3%E3%83%91%E3%82%A4%E3%83%AB%E3%81%A8%E3%83%87%E3%83%97%E3%83%AD%E3%82%A4%E3%83%9E%E3%82%A4%E3%82%B0%E3%83%AC%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3\"><\/span>\n\u30b3\u30f3\u30d1\u30a4\u30eb\u3068\u30c7\u30d7\u30ed\u30a4(\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n<h3><span class=\"ez-toc-section\" id=\"%E3%82%B3%E3%83%B3%E3%83%91%E3%82%A4%E3%83%AB\"><\/span>\n\u30b3\u30f3\u30d1\u30a4\u30eb<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li>\n<code>truffle compile<\/code>\u3067\u30b3\u30f3\u30d1\u30a4\u30eb\n\n<ul>\n<li>\u30d6\u30ed\u30c3\u30af\u30c1\u30a7\u30fc\u30f3\u5e38\u306b\u30c7\u30d7\u30ed\u30a4\u3055\u308c\u305f\u30d0\u30a4\u30c8\u30b3\u30fc\u30c9\u306f\u8ab0\u3067\u3082\u898b\u308c\u308b\u306e\u3067\u3001\u79d8\u5bc6\u306e\u60c5\u5831\u3092\u30cf\u30fc\u30c9\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3057\u306a\u3044\u3088\u3046\u306b\u6ce8\u610f\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n<h3><span class=\"ez-toc-section\" id=\"%E3%83%87%E3%83%97%E3%83%AD%E3%82%A4%E3%83%9E%E3%82%A4%E3%82%B0%E3%83%AC%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3\"><\/span>\n\u30c7\u30d7\u30ed\u30a4(\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li>\n<code>migrations\/2_deploy_contracts.js<\/code>\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3001\u4ee5\u4e0b\u3092\u8a18\u8ff0\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">var Adoption = artifacts.require(\"Adoption\");\n\nmodule.exports = function(deployer) {\n  deployer.deploy(Adoption);\n};<\/code><\/pre>\n\n\n\n<ul>\n<li>Mac\u30a2\u30d7\u30ea\u306eGanache\u3067\u3001\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u3067\u30d6\u30ed\u30c3\u30af\u30c1\u30a7\u30fc\u30f3\u3092\u8d77\u52d5\u3002<\/li>\n<\/ul>\n\n<p><a href=\"https:\/\/camo.qiitausercontent.com\/5827ffb3d01f33d0d55585184ffee5b1df69cdd3\/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e616d617a6f6e6177732e636f6d2f302f3134323537372f35633462356438622d396366632d346532362d633338622d3961323963363435343266652e706e67\" target=\"_blank\" rel=\"nofollow noopener\"><img decoding=\"async\" src=\"https:\/\/qiita-user-contents.imgix.net\/https%3A%2F%2Fqiita-image-store.s3.amazonaws.com%2F0%2F142577%2F5c4b5d8b-9cfc-4e26-c38b-9a29c64542fe.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=17f6d98be4d953213bc6420d243094bf\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2018-09-10 14.24.42.png\" data-canonical-src=\"https:\/\/qiita-image-store.s3.amazonaws.com\/0\/142577\/5c4b5d8b-9cfc-4e26-c38b-9a29c64542fe.png\" srcset=\"https:\/\/qiita-user-contents.imgix.net\/https%3A%2F%2Fqiita-image-store.s3.amazonaws.com%2F0%2F142577%2F5c4b5d8b-9cfc-4e26-c38b-9a29c64542fe.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&w=1400&fit=max&s=62c005b706f3c55aa5b66c28649fdfc8 1x\" loading=\"lazy\"><\/a><\/p>\n\n<p><a href=\"https:\/\/camo.qiitausercontent.com\/b9e5eddeb03b4e2b9e491e97c1a635214b338129\/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e616d617a6f6e6177732e636f6d2f302f3134323537372f39326564633731652d376236352d366238662d303261612d3766613937666631373638312e706e67\" target=\"_blank\" rel=\"nofollow noopener\"><img decoding=\"async\" src=\"https:\/\/qiita-user-contents.imgix.net\/https%3A%2F%2Fqiita-image-store.s3.amazonaws.com%2F0%2F142577%2F92edc71e-7b65-6b8f-02aa-7fa97ff17681.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=2910631efc1219b121a7974f69721e1f\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2018-09-10 14.26.07.png\" data-canonical-src=\"https:\/\/qiita-image-store.s3.amazonaws.com\/0\/142577\/92edc71e-7b65-6b8f-02aa-7fa97ff17681.png\" srcset=\"https:\/\/qiita-user-contents.imgix.net\/https%3A%2F%2Fqiita-image-store.s3.amazonaws.com%2F0%2F142577%2F92edc71e-7b65-6b8f-02aa-7fa97ff17681.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&w=1400&fit=max&s=d823a1c4ba95d91db748b847424e4c4b 1x\" loading=\"lazy\"><\/a><\/p>\n\n<ul>\n<li><p><code>truffle migrate<\/code>\u3067\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u5b9f\u65bd\u3002<\/p><\/li>\n<li><p>Ganache\u306e\u30a2\u30d7\u30ea\u4e0a\u3067\u3001\u30d6\u30ed\u30c3\u30af\u9ad8\u304c0\u304b\u30894\u306b\u306a\u3063\u305f\u306e\u3092\u78ba\u8a8d\u3002\u4e0a\u90e8\u30e1\u30cb\u30e5\u30fc\u306eBlocks\u3084Transactions\u3067\u6982\u8981\u3082\u78ba\u8a8d\u3002<\/p><\/li>\n<\/ul>\n\n<h2><span class=\"ez-toc-section\" id=\"%E3%83%86%E3%82%B9%E3%83%88\"><\/span>\n\u30c6\u30b9\u30c8<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n<p>\u30c6\u30b9\u30c8\u3092Solidity\u8a00\u8a9e\u3067\u66f8\u304f\u3002JavaScript\u3067\u3082\u66f8\u3051\u308b\u3002<\/p>\n\n<h3><span class=\"ez-toc-section\" id=\"%E3%83%86%E3%82%B9%E3%83%88%E3%81%AE%E4%BD%9C%E6%88%90\"><\/span>\n\u30c6\u30b9\u30c8\u306e\u4f5c\u6210<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li>test\/TestAdoption.sol\u3092\u4f5c\u6210\u3057\u3001\u4ee5\u4e0b\u3092\u8a18\u8ff0\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"text\" class=\"language-text\">pragma solidity ^0.4.17;\n\nimport \"truffle\/Assert.sol\";\nimport \"truffle\/DeployedAddresses.sol\";\nimport \"..\/contracts\/Adoption.sol\";\n\ncontract TestAdoption {\n  Adoption adoption = Adoption(DeployedAddresses.Adoption());   \/\/ \u30c6\u30b9\u30c8\u7528\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\n\n}<\/code><\/pre>\n\n\n\n<p>\u30c6\u30b9\u30c8\u306e\u305f\u3073\u306b\u30c7\u30d7\u30ed\u30a4\u304c\u884c\u308f\u308c\u308b\u305f\u3081\u3001<code>import \"truffle\/DeployedAddresses.sol\";<\/code>\u3067\u3001\u30c7\u30d7\u30ed\u30a4\u5148\u30a2\u30c9\u30ec\u30b9\u3092\u53d6\u5f97\u3059\u308b\u3002(<code>DeployedAddresses<\/code>\u3068\u3044\u3046\u7279\u6b8a\u306a\u5909\u6570?\u306b\u5165\u308b)<\/p>\n\n<h3><span class=\"ez-toc-section\" id=\"adopt%E9%96%A2%E6%95%B0%E3%81%AE%E3%83%86%E3%82%B9%E3%83%88\"><\/span>\nadopt()\u95a2\u6570\u306e\u30c6\u30b9\u30c8<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"text\" class=\"language-text\">  \/\/ Testing the adopt() function\n  function testUserCanAdoptPet() public {\n    uint returnedId = adoption.adopt(8);\n\n    uint expected = 8;\n\n    Assert.equal(returnedId, expected, \"Adoption of pet ID 8 should be recorded.\");\n  }<\/code><\/pre>\n\n\n\n<ul>\n<li>\n<code>Assert.equal(\u623b\u308a\u5024\u3001\u671f\u5f85\u5024\u3001\u5931\u6557\u3057\u305f\u6642\u306e\u30e1\u30c3\u30bb\u30fc\u30b8)<\/code>\u3067\u5224\u5b9a\u3002<\/li>\n<li>\u30da\u30c3\u30c8ID\u3092\u6e21\u3059\u3068(\u5b9f\u884c\u8005\u306e\u30a2\u30c9\u30ec\u30b9\u3092\u5909\u6570\u306b\u5165\u308c\u3066)\u30da\u30c3\u30c8ID\u3092\u8fd4\u3059\u95a2\u6570\u306a\u306e\u3067\u30018\u3092\u6e21\u3057\u305f\u30898\u304c\u8fd4\u308b\u3002<\/li>\n<\/ul>\n\n<h3><span class=\"ez-toc-section\" id=\"%E3%81%82%E3%82%8B%E4%B8%80%E5%8C%B9%E3%81%AE%E3%83%9A%E3%83%83%E3%83%88%E3%81%AE%E9%A3%BC%E3%81%84%E4%B8%BB%E3%82%92%E7%A2%BA%E8%AA%8D%E3%81%99%E3%82%8B%E3%83%86%E3%82%B9%E3%83%88\"><\/span>\n\u3042\u308b\u4e00\u5339\u306e\u30da\u30c3\u30c8\u306e\u98fc\u3044\u4e3b\u3092\u78ba\u8a8d\u3059\u308b\u30c6\u30b9\u30c8<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li>\u4e0a\u8ff0\u306e\u30c6\u30b9\u30c8\u95a2\u6570\u3067\u30018\u756a\u306e\u30da\u30c3\u30c8\u3092\u8cb7\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u306e\u72b6\u614b\u3092\u5229\u7528\u3057\u3066\u30018\u756a\u306e\u30da\u30c3\u30c8\u306e\u98fc\u3044\u4e3b\u304c\u81ea\u5206\u3067\u3042\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/li>\n<li>\n<code>this<\/code>\u306f\u3001\u30c6\u30b9\u30c8\u5b9f\u884c\u8005\u306e\u30a2\u30c9\u30ec\u30b9\u304c\u5165\u3063\u3066\u3044\u308b\u3002\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\uff1f<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"text\" class=\"language-text\">  \/\/ Testing retrieval of a single pet's owner(\u3042\u308b\u4e00\u5339\u306e\u30da\u30c3\u30c8\u306e\u98fc\u3044\u4e3b\u3092\u78ba\u8a8d\u3059\u308b\u30c6\u30b9\u30c8)\n  function testGetAdopterAddressByPetId() public {\n    \/\/ Expected owner is this contract\n    address expected = this;\n\n    address adopter = adoption.adopters(8);\n\n    Assert.equal(adopter, expected, \"Owner of pet ID 8 should be recorded.\");\n  }<\/code><\/pre>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"%E5%85%A8%E3%81%A6%E3%81%AE%E3%83%9A%E3%83%83%E3%83%88%E3%81%AE%E9%A3%BC%E3%81%84%E4%B8%BB%E3%82%92%E5%BE%97%E3%82%8B%E3%83%86%E3%82%B9%E3%83%88\"><\/span>\n\u5168\u3066\u306e\u30da\u30c3\u30c8\u306e\u98fc\u3044\u4e3b\u3092\u5f97\u308b\u30c6\u30b9\u30c8<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li>\n<code>memory<\/code>\u5c5e\u6027\u304c\u3064\u304f\u3068\u3001\u30e1\u30e2\u30ea\u4e0a\u306b\u4e00\u6642\u7684\u306b\u4fdd\u5b58\u3059\u308b\u5909\u6570\u3068\u306a\u308b\u3002(\u3064\u3051\u306a\u3044\u3068\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u4e0a\u306e\u5909\u6570\u306b\u306a\u308b(\u306e\u3067\u66f8\u304d\u8fbc\u307f\u306bgas\u4ee3\u304c\u304b\u304b\u308b?))<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"text\" class=\"language-text\">  \/\/ Testing retrieval of all pet owners(\u5168\u3066\u306e\u30da\u30c3\u30c8\u306e\u98fc\u3044\u4e3b\u3092\u5f97\u308b\u30c6\u30b9\u30c8)\n  function testGetAdopterAddressByPetIdInArray() public {\n    \/\/ Expected owner is this contract\n    address expected = this;\n\n    \/\/ Store adopters in memory rather than contract's storage\n    address[16] memory adopters = adoption.getAdopters();\n\n    Assert.equal(adopters[8], expected, \"Owner of pet ID 8 should be recorded.\");\n  }<\/code><\/pre>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"%E3%83%86%E3%82%B9%E3%83%88%E3%81%AE%E5%AE%9F%E8%A1%8C\"><\/span>\n\u30c6\u30b9\u30c8\u306e\u5b9f\u884c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li>\n<code>truffle test<\/code>\u3067\u30c6\u30b9\u30c8\u3092\u5b9f\u884c\u3002\n\n<ul>\n<li>3\u3064\u306e\u30c6\u30b9\u30c8\u5168\u3066\u306b\u30c1\u30a7\u30c3\u30af\u30de\u30fc\u30af\u304c\u3064\u3051\u3070OK\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n<h2><span class=\"ez-toc-section\" id=\"%E3%83%A6%E3%83%BC%E3%82%B6%E3%83%BC%E3%82%A4%E3%83%B3%E3%82%BF%E3%83%95%E3%82%A7%E3%83%BC%E3%82%B9%E3%81%AE%E4%BD%9C%E6%88%90\"><\/span>\n\u30e6\u30fc\u30b6\u30fc\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306e\u4f5c\u6210<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n<ul>\n<li>\n<code>src<\/code> \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u3001index.html\u3068\u753b\u50cf\u3084css\u306a\u3069\u304c\u4e00\u5f0f\u5165\u3063\u3066\u3044\u308b\u3002\u3000<\/li>\n<li>\n<p>\u30d6\u30e9\u30a6\u30b6\u753b\u9762\u306e\u4e3b\u306a\u6a5f\u80fd\u306f\u4ee5\u4e0b\u306e3\u3064\u3002<\/p>\n\n<ul>\n<li>\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u30da\u30c3\u30c8\u306e\u540d\u524d\u306a\u3069\u306e\u60c5\u5831\u3092\u8aad\u307f\u8fbc\u3093\u3067\u8868\u793a\u3002<\/li>\n<li>\u30d6\u30ed\u30c3\u30af\u30c1\u30a7\u30fc\u30f3\u4e0a\u306e\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u5185\u306e\u5909\u6570\u3092\u53d6\u308a\u51fa\u3057\u3066\u3001\u98fc\u3044\u4e3b\u304c\u3044\u308b\u30da\u30c3\u30c8\u306f\u30dc\u30bf\u30f3\u3092\u62bc\u305b\u306a\u304f\u3059\u308b\u3002<\/li>\n<li>\u30dc\u30bf\u30f3\u304c\u62bc\u3055\u308c\u305f\u3089\u3001\u30da\u30c3\u30c8\u3092\u8cb7\u3063\u305f\u98fc\u3044\u4e3b\u306e\u60c5\u5831\u3092\u30d6\u30ed\u30c3\u30af\u30c1\u30a7\u30fc\u30f3\u4e0a\u306b\u66f8\u304d\u8fbc\u307f\u3001\u30dc\u30bf\u30f3\u3092\u62bc\u305b\u306a\u304f\u3059\u308b\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><code>src\/js\/app.js<\/code> \u3092\u66f8\u304d\u63db\u3048\u3066\u3044\u304f\u3002<\/p>\n\n<ul>\n<li>\n<code>App<\/code>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u30a2\u30d7\u30ea\u3092\u64cd\u4f5c\u3067\u304d\u308b\u3002(\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570?)<\/li>\n<li>\n<code>init\u95a2\u6570<\/code>\u3067\u3001json\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u30da\u30c3\u30c8\u60c5\u5831\u3092\u8aad\u307f\u51fa\u3057\u3066\u3001<code>initWeb3<\/code>\u95a2\u6570\u3092\u547c\u3073\u51fa\u3057\u3066\u3044\u308b\u3002<\/li>\n<li>markAdopted\u95a2\u6570\u3067\u3001\u8cb7\u3044\u624b\u306e\u3064\u3044\u305f\u30da\u30c3\u30c8\u3092\u8abf\u3079\u3001\u8868\u793a\u3092\u5909\u3048\u3066\u3044\u308b\u3002<\/li>\n<li>handleAdopt\u95a2\u6570\u3067\u3001\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u3066\u30da\u30c3\u30c8\u3092\u8cb7\u3063\u305f\u6642\u306e\u51e6\u7406\u3092\u884c\u3063\u3066\u3044\u308b\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n<h3><span class=\"ez-toc-section\" id=\"web3%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB\"><\/span>\nweb3\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li><p><a href=\"https:\/\/github.com\/ethereum\/web3.js\/\" rel=\"nofollow noopener\" target=\"_blank\">web3<\/a>\u306f\u3001Ethereum\u306e\u30ce\u30fc\u30c9\u3068HTTP\u306a\u3069\u3067\u3084\u308a\u53d6\u308a\u3059\u308b\u305f\u3081\u306eJavaScript\u30e9\u30a4\u30d6\u30e9\u30ea\u3002 (<a href=\"https:\/\/web3js.readthedocs.io\/en\/1.0\/index.html#\" rel=\"nofollow noopener\" target=\"_blank\">\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a>\u304c\u3042\u308b\u306e\u3067\u53c2\u7167)<\/p><\/li>\n<li><p><code>npm install -g web3<\/code>\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u304f\u3002<\/p><\/li>\n<\/ul>\n\n<h3><span class=\"ez-toc-section\" id=\"initWeb3%E9%96%A2%E6%95%B0%E3%81%AE%E5%AE%9F%E8%A3%85\"><\/span>\ninitWeb3\u95a2\u6570\u306e\u5b9f\u88c5<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li>\u30b3\u30e1\u30f3\u30c8\u304c\u5165\u3063\u3066\u3044\u308b\u306e\u3092\u6d88\u3057\u3066\u3001\u4ee5\u4e0b\u306b\u66f8\u304d\u63db\u3048\u308b\u3002\n\n<ul>\n<li>web3\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u3042\u308c\u3070\u305d\u308c\u3092\u4f7f\u3044\u3001\u306a\u3051\u308c\u3070\u5b9f\u4f53\u5316\u3059\u308b\u51e6\u7406\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"text\" class=\"language-text\">  initWeb3: function() {\n    \/\/ Is there an injected web3 instance?\n    if (typeof web3 !== 'undefined') {\n      App.web3Provider = web3.currentProvider;\n    } else {\n      \/\/ If no injected web3 instance is detected, fall back to Ganache\n      App.web3Provider = new Web3.providers.HttpProvider('http:\/\/localhost:7545');\n    }\n    web3 = new Web3(App.web3Provider);\n\n    return App.initContract();\n  },<\/code><\/pre>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"%E3%82%B3%E3%83%B3%E3%83%88%E3%83%A9%E3%82%AF%E3%83%88%E3%81%AE%E5%AE%9F%E4%BD%93%E5%8C%96\"><\/span>\n\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u306e\u5b9f\u4f53\u5316<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li>\n<code>TruffleContract\u95a2\u6570<\/code>\u304c\u3042\u308b\u306e\u3067\u3001\u30c7\u30d7\u30ed\u30a4\u5148\u306e\u30a2\u30c9\u30ec\u30b9\u3092\u3044\u3061\u3044\u3061\u66f8\u304d\u63db\u3048\u306a\u3044\u3067\u3059\u3080(?)<\/li>\n<li>\n<code>initContract\u95a2\u6570<\/code>\u3092\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304d\u63db\u3048\u3002\n\n<ul>\n<li>\u95a2\u6570\u5185\u3067\u8aad\u307f\u8fbc\u3093\u3067\u3044\u308b<code>Adoption.json<\/code>\u306fbuild\/contracts\/Adoption.json\u306b\u3042\u308b\u3002<\/li>\n<li>Application Binary Interface (ABI)\u306f\u3001\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u3068\u5bfe\u8a71(\u95a2\u6570\u3084\u5909\u6570\u3078\u306e\u30a2\u30af\u30bb\u30b9)\u3059\u308b\u305f\u3081\u306e\u30a2\u30c9\u30ec\u30b9\u3002<\/li>\n<li>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3055\u308c\u308b\u3068\u3001\u4e0a\u8ff0\u306eApp.web3Provider\u3092\u4f7f\u3063\u3066\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\uff1f<\/li>\n<li>\u6700\u5f8c\u306e\u884c\u306e<code>App.markAdopted();<\/code>\u306f\u3001\u3059\u3067\u306b\u8cb7\u3044\u624b\u306e\u3064\u3044\u305f(=\u914d\u5217\u5185\u306e\u6240\u5b9a\u306e\u4f4d\u7f6e\u306b\u98fc\u3044\u4e3b\u306e\u30a2\u30c9\u30ec\u30b9\u304c\u5165\u3063\u3066\u3044\u308b\uff1f)\u30da\u30c3\u30c8\u3092\u3001\u8868\u793a\u3092\u5909\u3048\u308b\u305f\u3081\u306e\u95a2\u6570\u3002(\u6b21\u306e\u6bb5\u843d\u3067\u5b9f\u88c5)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"text\" class=\"language-text\">  initContract: function() {\n    $.getJSON('Adoption.json', function(data) {\n      \/\/ Get the necessary contract artifact file and instantiate it with truffle-contract\n      var AdoptionArtifact = data;\n      App.contracts.Adoption = TruffleContract(AdoptionArtifact);\n\n      \/\/ Set the provider for our contract\n      App.contracts.Adoption.setProvider(App.web3Provider);\n\n      \/\/ Use our contract to retrieve and mark the adopted pets\n      return App.markAdopted();\n    });\n\n    return App.bindEvents();\n  },<\/code><\/pre>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"%E8%B2%B7%E3%81%84%E6%89%8B%E3%81%AE%E3%81%A4%E3%81%84%E3%81%9F%E3%83%9A%E3%83%83%E3%83%88%E3%82%92%E8%AA%BF%E3%81%B9%E3%80%81%E8%A1%A8%E7%A4%BA%E3%82%92%E5%A4%89%E3%81%88%E3%82%8B\"><\/span>\n\u8cb7\u3044\u624b\u306e\u3064\u3044\u305f\u30da\u30c3\u30c8\u3092\u8abf\u3079\u3001\u8868\u793a\u3092\u5909\u3048\u308b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li>\n<code>markAdopted\u95a2\u6570<\/code>\u3092\u3001\u30b3\u30e1\u30f3\u30c8\u3092\u6d88\u3057\u3066\u4ee5\u4e0b\u306b\u66f8\u304d\u63db\u3048\u308b\u3002\n\n<ul>\n<li>\n<code>call()<\/code>\u3092\u4f7f\u3063\u3066\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u306e\u5909\u6570\u3092\u53d6\u308a\u51fa\u3057\u3066\u3044\u308b(gas\u4ee3\u306f\u304b\u304b\u3089\u306a\u3044)<\/li>\n<li>Ethereum\u3067\u306f\u6700\u521d\u306b\u5909\u6570\u3092\u30bc\u30ed\u30af\u30ea\u30a2\u3059\u308b\u306e\u3067\u3001\u8cb7\u3044\u624b\u304c\u3064\u3044\u305f(\u30a2\u30c9\u30ec\u30b9\u304c\u5165\u3063\u305f)\u304b\u3069\u3046\u304b\u3092\u30010\u3068\u6bd4\u8f03\u3057\u3066\u5224\u65ad\u3067\u304d\u308b\u3002<\/li>\n<li>\u30a8\u30e9\u30fc\u304c\u3042\u308c\u3070\u3001(\u30d6\u30e9\u30a6\u30b6\u306e)console\u30ed\u30b0\u306b\u51fa\u529b\u3059\u308b\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"text\" class=\"language-text\">  markAdopted: function(adopters, account) {\n    var adoptionInstance;\n\n    \/\/ \u30c7\u30d7\u30ed\u30a4\u3057\u305f\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u306egetAdopters\u95a2\u6570\u3092call\u3059\u308b\n    App.contracts.Adoption.deployed().then(function(instance) {\n      adoptionInstance = instance;\n\n      return adoptionInstance.getAdopters.call();\n    }).then(function(adopters) {\n      \/\/ adopters\u3092\u9806\u756a\u306b\u53d6\u308a\u51fa\u3057\u30010\u4ee5\u5916(=\u3059\u3067\u306b\u8cb7\u3044\u624b\u304c\u3064\u3044\u3066\u3044\u308b)\u306e\u5834\u5408\u306f\u3001\n      \/\/ \u30dc\u30bf\u30f3\u306e\u6587\u5b57\u5217\u3092'Success'\u306b\u3057\u3066\u3001disabled\u8868\u793a\u306b\u3059\u308b\n      for (i = 0; i < adopters.length; i++) {\n        if (adopters[i] !== '0x0000000000000000000000000000000000000000') {\n          $('.panel-pet').eq(i).find('button').text('Success').attr('disabled', true);\n        }\n      }\n    }).catch(function(err) {\n      console.log(err.message);\n    });\n  },<\/code><\/pre>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"%E3%83%9A%E3%83%83%E3%83%88%E3%82%92%E8%B2%B7%E3%81%A3%E3%81%9F%E6%99%82%E3%81%AE%E5%87%A6%E7%90%86%E3%83%96%E3%83%A9%E3%82%A6%E3%82%B6%E3%81%8B%E3%82%89%E3%83%9C%E3%82%BF%E3%83%B3%E3%82%92%E6%8A%BC%E3%81%97%E3%81%A6%E8%B2%B7%E3%81%86\"><\/span>\n\u30da\u30c3\u30c8\u3092\u8cb7\u3063\u305f\u6642\u306e\u51e6\u7406(\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u3066\u8cb7\u3046)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li>\n<code>handleAdopt\u95a2\u6570<\/code>\u3092\u3001\u30b3\u30e1\u30f3\u30c8\u3092\u6d88\u3057\u3066\u4ee5\u4e0b\u306b\u66f8\u304d\u63db\u3048\u308b\u3002(\u4e00\u756a\u5f8c\u308d\u306e\u95a2\u6570\u306a\u306e\u3067\u3001\u6700\u5f8c\u306e\u6ce2\u9589\u3058\u30ab\u30c3\u30b3\u306e\u5f8c\u306b\u30ab\u30f3\u30de\u3092\u3064\u3051\u306a\u3044)\n\n<ul>\n<li>\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u306eadopt\u95a2\u6570\u3092\u3001petId\u3068\u81ea\u5206\u306e\u30a2\u30c9\u30ec\u30b9\u3092\u3064\u3051\u3066\u547c\u3073\u51fa\u3057\u3066\u3044\u308b(\u8cb7\u3063\u305f\u6642\u306b\u3001\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u5185\u306e\u914d\u5217\u306b\u5024\u3092\u5165\u308c\u308b\u305f\u3081)(gas\u4ee3\u304c\u304b\u304b\u308b)<\/li>\n<li>\u3046\u307e\u304f\u3044\u3063\u305f\u3089\u3001\u8868\u793a\u3092\u66f8\u304d\u63db\u3048\u308b\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"text\" class=\"language-text\">  handleAdopt: function(event) {\n    event.preventDefault();\n\n    \/\/ \u9078\u629e\u3057\u305f(\u62bc\u3055\u308c\u305f\u30dc\u30bf\u30f3\u306e)id\u3092petId\u306b\u3059\u308b\n    var petId = parseInt($(event.target).data('id'));\n\n    var adoptionInstance;\n\n    \/\/ (\u5b9f\u884c\u8005\u306e?)\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u53d6\u5f97\n    web3.eth.getAccounts(function(error, accounts) {\n      if (error) {\n        console.log(error);\n      }\n\n      var account = accounts[0];\n\n      App.contracts.Adoption.deployed().then(function(instance) {\n        adoptionInstance = instance;\n\n        \/\/ Execute adopt as a transaction by sending account\n        \/\/ \u73fe\u5728\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u4f7f\u3063\u3066\u3001\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u306eadopt\u95a2\u6570\u3092\u547c\u3073\u51fa\u3057\u3001\u914d\u5217\u306b\u30a2\u30c9\u30ec\u30b9\u3092\u5165\u308c\u308b\u3002\n        return adoptionInstance.adopt(petId, {from: account});\n      }).then(function(result) {\n        \/\/ \u8868\u793a\u3092\u5909\u66f4(\u30dc\u30bf\u30f3\u306e\u6587\u5b57\u5217\u3092'Success'\u306b\u3057\u3066\u3001disabled\u8868\u793a\u306b\u3059\u308b)\n        return App.markAdopted();\n      }).catch(function(err) {\n        console.log(err.message);\n      });\n    });\n  }<\/code><\/pre>\n\n\n\n<h2><span class=\"ez-toc-section\" id=\"%E3%83%96%E3%83%A9%E3%82%A6%E3%82%B6%E3%81%8B%E3%82%89%E5%8B%95%E4%BD%9C%E7%A2%BA%E8%AA%8D\"><\/span>\n\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u52d5\u4f5c\u78ba\u8a8d<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n<h3><span class=\"ez-toc-section\" id=\"Metamask%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E3%81%A8%E8%A8%AD%E5%AE%9A\"><\/span>\nMetamask\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u8a2d\u5b9a<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li><p>chrome\u30d6\u30e9\u30a6\u30b6\u306b<a href=\"https:\/\/metamask.io\/\" rel=\"nofollow noopener\" target=\"_blank\">Metamask<\/a>\u30a8\u30af\u30b9\u30c6\u30f3\u30b7\u30e7\u30f3\u3092\u5165\u308c\u308b<\/p><\/li>\n<li><p>Ganache\u306e\u300cAccounts\u300d\u30bf\u30d6\u306e\u4e0a\u306e\u65b9\u306b\u3042\u308b\u30cb\u30fc\u30e2\u30cb\u30c3\u30af\u3092\u30b3\u30d4\u30fc\u3002<\/p><\/li>\n<li><p>Metamask\u306e\u300cRestore from seed phrase\u300d\u3092\u30af\u30ea\u30c3\u30af<\/p><\/li>\n<li><p>\u300cWallet seed\u300d\u6b04\u306b\u5165\u529b\u3057\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u3082\u5165\u529b<\/p><\/li>\n<li><p>\u5de6\u4e0a\u306e\u30bb\u30ec\u30af\u30c8\u30dc\u30c3\u30af\u30b9\u3067\u300cCustom RPC\u300d\u3092\u9078\u629e\u3002Ganache\u3067\u7acb\u3061\u4e0a\u3052\u305f\u30b5\u30fc\u30d0\u306e\u300c<a href=\"http:\/\/127.0.0.1:7545\/\" class=\"autolink\" rel=\"nofollow noopener\" target=\"_blank\">http:\/\/127.0.0.1:7545\/<\/a> \u300d\u3092\u5165\u529b\u3057\u3066Save\u3002(\u672b\u5c3e\u306b\u300c\/\u300d\u3092\u4ed8\u3051\u306a\u3044\u3068\u3001\u518d\u8d77\u52d5\u6642\u306b\u300cConnecting to Unknown Private Network\u300d\u3067\u5f85\u305f\u3055\u308c\u308b)<\/p><\/li>\n<li><p>\u5de6\u77e2\u5370\u30dc\u30bf\u30f3\u3067\u623b\u308b\u3068\u3001Ganache\u306e\u4e00\u756a\u4e0a\u306b\u3042\u308b\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u6b8b\u9ad8\u304cMetamask\u5074\u306b\u3082\u53cd\u6620\u3055\u308c\u3066\u3044\u308b\u3002<\/p><\/li>\n<\/ul>\n\n<h3><span class=\"ez-toc-section\" id=\"lite-server%E3%81%AE%E8%B5%B7%E5%8B%95\"><\/span>\nlite-server\u306e\u8d77\u52d5<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li>\n<p><code>npm run dev<\/code>\u3067\u3001\u30b5\u30fc\u30d0\u304c\u7acb\u3061\u4e0a\u304c\u308a\u3001\u81ea\u52d5\u7684\u306b\u30d6\u30e9\u30a6\u30b6\u304c\u958b\u304f\u3002<\/p>\n\n<ul>\n<li>\u3059\u3067\u306blite-server\u30e2\u30b8\u30e5\u30fc\u30eb\u304cnode_modules\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b\u3002<\/li>\n<li>\n<code>bs-config.json<\/code>\u30d5\u30a1\u30a4\u30eb\u3067\u3001html\u30bd\u30fc\u30b9\u306e\u5834\u6240\u3084\u3001\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u306e\u5834\u6240\u3092\u6307\u5b9a\u3059\u308b\u3002<\/li>\n<li>\n<code>package.json<\/code>\u30d5\u30a1\u30a4\u30eb\u3067\u3001npm\u306edev\u30b3\u30de\u30f3\u30c9\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u3002<\/li>\n<\/ul>\n<\/li>\n<li><p>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067Safari\u304c\u8d77\u52d5\u3059\u308b\u306e\u3067\u3001\u624b\u52d5\u3067Chrome\u304b\u3089<a href=\"http:\/\/localhost:3000\" class=\"autolink\" rel=\"nofollow noopener\" target=\"_blank\">http:\/\/localhost:3000<\/a> \u3092\u958b\u304f\u3002<\/p><\/li>\n<li><p>JavaScript\u30b3\u30f3\u30bd\u30fc\u30eb\u3092\u958b\u3044\u3066\u3001\u30a8\u30e9\u30fc\u304c\u51fa\u3066\u3044\u306a\u3044\u304b\u78ba\u8a8d\u3059\u308b\u3002<\/p><\/li>\n<li>\n<p>Adopt\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u3001Metamask\u306e\u753b\u9762\u304c\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u3059\u308b\u306e\u3067\u3001\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u5185\u5bb9\u3092\u78ba\u8a8d\u3057\u3066\u3001SUBMIT\u3092\u62bc\u3059\u3002<\/p>\n\n<ul>\n<li>Ganache\u3067\u3001\u30d6\u30ed\u30c3\u30af\u304c\u9032\u3093\u3067\u3044\u308b\u306e\u3082\u78ba\u8a8d\u3059\u308b\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n<h2><span class=\"ez-toc-section\" id=\"Mac%E3%82%92%E5%86%8D%E8%B5%B7%E5%8B%95%E3%81%97%E3%81%9F%E5%A0%B4%E5%90%88\"><\/span>\nMac\u3092\u518d\u8d77\u52d5\u3057\u305f\u5834\u5408<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n<ul>\n<li>Ganache\u8d77\u52d5<\/li>\n<li>\n<code>truffle migrate --reset<\/code> (\u300c\u2013reset\u300d\u3067\u3001build\u914d\u4e0b\u306e\u30d0\u30a4\u30c8\u30b3\u30fc\u30c9\u3068\u304b\u306ejson\u3092\u30af\u30ea\u30a2\u3057\u3066\u304b\u3089\u5b9f\u884c\u3057\u3066\u304f\u308c\u308b)<\/li>\n<li>Metamask\u306e\u753b\u9762\u3092\u958b\u3044\u3066\u3001Account1\u3092\u8868\u793a\u3059\u308b\u3002\n\n<ul>\n<li>\u300cConnecting to Unknown Private Network\u300d\u306e\u307e\u307e\u306e\u5834\u5408\u306f\u3001\u5de6\u4e0a\u306e\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u8a2d\u5b9a\u3092\u3001\u4e00\u65e6\u5225\u306a\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u3092\u9078\u3093\u3067\u3001\u518d\u5ea6\u300c<a href=\"http:\/\/127.0.0.1:7545\/\" class=\"autolink\" rel=\"nofollow noopener\" target=\"_blank\">http:\/\/127.0.0.1:7545\/<\/a> \u300d\u3092\u9078\u629e<\/li>\n<li>\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u308c\u308b(\u300cRestore from seed phrase\u300d\u3067\u767b\u9332\u3057\u305f\u6642\u306b\u4f7f\u3063\u305f\u30d1\u30b9\u30ef\u30fc\u30c9)<\/li>\n<\/ul>\n<\/li>\n<li>Metamask\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u30ea\u30bb\u30c3\u30c8\u3059\u308b\u3002\u300cAccount1\u300d\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u72b6\u614b\u3067\u3001\u53f3\u4e0a\u306e\u30e1\u30cb\u30e5\u30fc\u304b\u3089\u300cSettings\u300d\u3067\u3001\u4e0b\u306e\u65b9\u306b\u3042\u308b\u300cReset Account\u300d\u3092\u30af\u30ea\u30c3\u30af\u3002<\/li>\n<li>\n<code>npm run dev<\/code> \u3067\u30b5\u30fc\u30d0\u8d77\u52d5<\/li>\n<li>Chrome\u3067 <a href=\"http:\/\/localhost:3000\" class=\"autolink\" rel=\"nofollow noopener\" target=\"_blank\">http:\/\/localhost:3000<\/a> \u3092\u958b\u304f<\/li>\n<\/ul>\n\n<h3>\n\u521d\u56de\u306eAdopt\u3067?\u3001\u30dc\u30bf\u30f3\u304c\u2019Success\u2019\u306b\u306a\u3089\u306a\u3044<\/h3>\n\n<ul>\n<li>\u8d77\u52d5\u76f4\u5f8c\u306b\u300cAdopt\u300d\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u3001\u30d6\u30ed\u30c3\u30af\u30c1\u30a7\u30fc\u30f3\u306b\u66f8\u304d\u8fbc\u307e\u308c\u305f\u306e\u304cGanache\u306eBLOCKS\u304b\u3089\u78ba\u8a8d\u3067\u304d\u307e\u3059\u304c\u3001\u753b\u9762\u4e0a\u306e\u30dc\u30bf\u30f3\u304c\u3059\u3050\u306b\u306f\u2019Success\u2019\u306b\u306a\u308a\u307e\u305b\u3093\u3002\u30ea\u30ed\u30fc\u30c9\u3059\u308b\u3068\u53cd\u6620\u3055\u308c\u307e\u3059\u30022\u56de\u76ee\u4ee5\u964d\u306eAdopt\u306f\u5373\u53cd\u6620\u3055\u308c\u308b\u5834\u5408\u3082\u3042\u308c\u3070\u3001\u30ea\u30ed\u30fc\u30c9\u3057\u306a\u3044\u3068\u53cd\u6620\u3055\u308c\u306a\u3044\u5834\u5408\u3082\u3042\u308a\u307e\u3059\u3002setInterval\u306715\u79d2\u5f85\u3063\u3066\u304b\u3089App.markAdopted();\u3092\u547c\u3076\u3088\u3046\u306b\u3057\u305f\u3089\u53cd\u6620\u3055\u308c\u307e\u3057\u305f\u3002adoptionInstance.adopt()\u3067\u30d6\u30ed\u30c3\u30af\u30c1\u30a7\u30fc\u30f3\u306b\u66f8\u304d\u8fbc\u3080\u306e\u304c\u975e\u540c\u671f\u306a\u6c17\u304c\u3057\u3066\u3044\u307e\u3059\u3002<\/li>\n<\/ul>\n\n<h3><span class=\"ez-toc-section\" id=\"nonce%E3%81%8C%E9%81%95%E3%81%86%E3%81%A8%E3%81%84%E3%81%86%E3%82%A8%E3%83%A9%E3%83%BC%E3%81%8C%E5%87%BA%E3%81%9F%E5%A0%B4%E5%90%88\"><\/span>\nnonce\u304c\u9055\u3046\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u51fa\u305f\u5834\u5408<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<ul>\n<li>Adopt\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u969b\u306b\u3001\u300c<code>Error: Error: [ethjs-rpc] rpc error with payload {\u2026once. account has nonce of: 8 tx has nonce of: 46<\/code>\u300d\u3084\u300c<code>Error: the tx doesn't have the correct nonce. account has nonce of: 4 tx has nonce of: 10<\/code>\u300d\u306e\u3088\u3046\u306b\u3001nonce\u304c\u9055\u3046\u3068\u51fa\u308b\u5834\u5408\u306f\u3001Metamask\u4e0a\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u30ea\u30bb\u30c3\u30c8\u3059\u308b\u3002<a href=\"https:\/\/consensys.zendesk.com\/hc\/en-us\/articles\/360004177531-Resetting-an-Account-New-UI-\" rel=\"nofollow noopener\" target=\"_blank\">Resetting an Account (New UI)<\/a>\n\n<ul>\n<li>\n<\/li><\/ul>\n<\/li>\n<\/ul>\n\n<h2><span class=\"ez-toc-section\" id=\"%E9%81%AD%E9%81%87%E3%81%97%E3%81%9F%E3%82%A8%E3%83%A9%E3%83%BC\"><\/span>\n\u906d\u9047\u3057\u305f\u30a8\u30e9\u30fc<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n<ul>\n<li>\u30c7\u30d7\u30ed\u30a4\u7528\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u3001deploy\u306e\u5f15\u6570\u306b\u5909\u6570\u3092\u6e21\u3057\u3066\u3044\u308b\u304c\u3001<code>deployer.deploy(Adoption);<\/code>\u3068\u66f8\u304f\u3079\u304d\u3092<code>deployer.deploy(\"Adoption\");<\/code>\u3068\u66f8\u3044\u3066\u3044\u305f\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"text\" class=\"language-text\">Running migration: 2_deploy_contracts.js\nError encountered, bailing. Network state unknown. Review successful transactions manually.<\/code><\/pre>\n\n\n\n<ul>\n<li>\u30c6\u30b9\u30c8\u3067Assert.equal()\u3092Assert()\u3068\u66f8\u3044\u3066\u3066\u30a8\u30e9\u30fc\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"text\" class=\"language-text\">test\/TestAdoption.sol:28:5: TypeError: Exactly one argument expected for explicit type conversion.\n    Assert(adopters[8], expected, \"Owner of pet ID 8 should be recorded.\");\n    ^--------------------------------------------------------------------^\nCompilation failed. See above.<\/code><\/pre>\n\n\n","protected":false},"excerpt":{"rendered":"<ul>\n<li>\u6a5f\u80fd\u3092\u9650\u5b9a\u3057\u305f\u30da\u30c3\u30c8\u30b7\u30e7\u30c3\u30d7\u306e\u30b7\u30b9\u30c6\u30e0\u3002<\/li>\n<li>\u30da\u30c3\u30c8\u306f16\u5339\u3044\u308b\u3002<\/li>\n<li>\u30d6\u30e9\u30a6\u30b6\u3067\u30da\u30c3\u30c8\u4e00\u89a7\u304c\u898b\u308c\u3066\u3001\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u8cb7\u3048\u308b\u3002<\/li>\n<li>\u30da\u30c3\u30c8\u306e\u4ee3\u91d1\u306f\u7121\u6599\u3002<\/li>\n<li>\u8ca9\u58f2\u306e\u307f\u3067\u8cb7\u53d6\u306f\u3057\u306a\u3044\u3002<\/li>\n<li>\u98fc\u3044\u4e3b\u306e\u533a\u5225\u306f\u30a2\u30ab\u30a6\u30f3\u30c8(\u30a2\u30c9\u30ec\u30b9?)\u3067\u884c\u3046\u3002<\/li>\n<\/ul>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4204,4227,4226],"tags":[4200,4225,4224],"class_list":["post-6063","post","type-post","status-publish","format-standard","hentry","category-ethereum","category-truffle","category-tutorial","tag-ethereum","tag-truffle","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=\/wp\/v2\/posts\/6063","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6063"}],"version-history":[{"count":0,"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=\/wp\/v2\/posts\/6063\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}