{"id":1824,"date":"2018-02-08T22:25:16","date_gmt":"2018-02-08T22:25:16","guid":{"rendered":"http:\/\/www.talkcrypto.org\/blog\/?p=1824"},"modified":"2018-02-14T04:07:59","modified_gmt":"2018-02-14T04:07:59","slug":"connecting-geth-to-metamask-and-mist","status":"publish","type":"post","link":"https:\/\/www.talkcrypto.org\/blog\/2018\/02\/08\/connecting-geth-to-metamask-and-mist\/","title":{"rendered":"Connecting Geth to MetaMask and Mist"},"content":{"rendered":"<p>If you have geth, the Go Ethereum client running and you want to connect Mist or MetaMask to you get a nice front end, here is how you do it.<\/p>\n<p>Start geth with:<\/p>\n<pre>&gt;\u00a0<span class=\"s1\">geth --datadir .\/chaindata init .\/myGenesisFile.json<\/span><\/pre>\n<p>Note: If you don&#8217;t have a genesis file, one is provided at the end.<\/p>\n<p>The run<\/p>\n<pre>&gt;\u00a0<span class=\"s1\">geth --datadir .\/chaindata --networkid 1994<\/span><\/pre>\n<p>to spin up the private Ethereum blockchain<\/p>\n<h3>Mist<\/h3>\n<p>The easiest way to connect Mist to this private blockchain is to start it via command line and passing in the location of the ipc file with the rpc flag.<\/p>\n<pre class=\"p1\"><span class=\"s1\">&gt; .\/Mist --rpc \/Users\/cloudnthings\/privatechain\/chaindata\/geth.ipc<\/span><\/pre>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-medium wp-image-1827\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-09-at-11.24.23-AM-300x172.png\" alt=\"\" width=\"300\" height=\"172\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-09-at-11.24.23-AM-300x172.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-09-at-11.24.23-AM.png 396w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>You should get the word PRIVATE-NET at the top. Click Launch Application and you should be away.<\/p>\n<p>If you get this error:<\/p>\n<p class=\"p1\"><span class=\"s1\">NCAUGHT EXCEPTION { Error: connect ENOENT Users\/cloudnthings\/privatechain\/chaindata\/geth.ipc<\/span><\/p>\n<p>Then it means you have your syntax wrong. The most common mistake is not having a double dash before rpc (- &#8211; rpc)<\/p>\n<h3>MetaMask<\/h3>\n<p>To connect to MetaMask, you need to start the private Ethereum blockchain with an extra rpc flag.<\/p>\n<pre>&gt;\u00a0<span class=\"s1\">geth --datadir .\/chaindata --networkid 1994 --rpc<\/span><\/pre>\n<p>You can connect to the blockchain as per normal via geth attach like so:<\/p>\n<pre>&gt;\u00a0<span class=\"s1\">geth attach http:\/\/127.0.0.1:8545<\/span><\/pre>\n<p>or in MetaMask, simple choose localhost<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-medium wp-image-1825\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-09-at-11.09.22-AM-227x300.png\" alt=\"\" width=\"227\" height=\"300\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-09-at-11.09.22-AM-227x300.png 227w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-09-at-11.09.22-AM.png 271w\" sizes=\"(max-width: 227px) 100vw, 227px\" \/><\/p>\n<p>The balance will be zero so be sure to import an account<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1826\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-09-at-11.10.22-AM.png\" alt=\"\" width=\"226\" height=\"262\" \/><\/p>\n<p>and find the JSON keystore file which you can locate in the folder where your private chain data is sitting.<\/p>\n<p>You should then be able to run<\/p>\n<pre>&gt;\u00a0<span class=\"s1\">web3.eth.accounts<\/span><\/pre>\n<p>to confirm the public address is the same and then<\/p>\n<pre><span class=\"s1\">&gt; eth.getBalance(web3.eth.accounts[0])<\/span><\/pre>\n<p>where the 2 balances should match.<\/p>\n<p>A neat extension to this is to try mining and seeing the balance increase. Unfortunately Web3 does not expose the miner object via <a href=\"https:\/\/ethereum.stackexchange.com\/questions\/12098\/can-i-mine-on-my-private-blockchain-using-geth-with-rpc\" target=\"_blank\" rel=\"noopener\">rpc<\/a> so you&#8217;ll have to connect via ipc like so:<\/p>\n<pre>&gt;\u00a0<span class=\"s1\">geth attach ipc:\/Users\/cloudnthings\/privatechain\/chaindata\/geth.ipc<\/span><\/pre>\n<p>and then run miner.start() and miner.stop(). If you watch MetaMask you&#8217;ll see the balance jump up in real time!<\/p>\n<h3>Genesis file sample<\/h3>\n<pre class=\" hljs json\">{\r\n   \"<span class=\"hljs-attribute\">config<\/span>\": <span class=\"hljs-value\">{\r\n      \"<span class=\"hljs-attribute\">chainId<\/span>\": <span class=\"hljs-number\">1994<\/span>,\r\n      \"<span class=\"hljs-attribute\">homesteadBlock<\/span>\": <span class=\"hljs-number\">0<\/span>,\r\n      \"<span class=\"hljs-attribute\">eip155Block<\/span>\": <span class=\"hljs-number\">0<\/span>,\r\n      \"<span class=\"hljs-attribute\">eip158Block<\/span>\": <span class=\"hljs-number\">0<\/span>,\r\n      \"<span class=\"hljs-attribute\">byzantiumBlock<\/span>\": <span class=\"hljs-number\">0<\/span>\r\n   }<\/span>,\r\n   \"<span class=\"hljs-attribute\">difficulty<\/span>\": <span class=\"hljs-value\"><span class=\"hljs-string\">\"400\"<\/span><\/span>,\r\n   \"<span class=\"hljs-attribute\">gasLimit<\/span>\": <span class=\"hljs-value\"><span class=\"hljs-string\">\"2000000\"<\/span><\/span>,\r\n   \"<span class=\"hljs-attribute\">alloc<\/span>\": <span class=\"hljs-value\">{\r\n      \"<span class=\"hljs-attribute\">7b684d27167d208c66584ece7f09d8bc8f86ffff<\/span>\": { \r\n          \"<span class=\"hljs-attribute\">balance<\/span>\": <span class=\"hljs-string\">\"100000000000000000000000\"<\/span> \r\n      }\r\n   }\r\n<\/span>}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you have geth, the Go Ethereum client running and<\/p>\n","protected":false},"author":1,"featured_media":1829,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1824","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ethereum"],"featured_image_urls":{"full":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/geth.jpg",300,203,false],"thumbnail":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/geth-150x150.jpg",150,150,true],"medium":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/geth-300x203.jpg",300,203,true],"medium_large":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/geth.jpg",300,203,false],"large":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/geth.jpg",300,203,false],"1536x1536":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/geth.jpg",300,203,false],"2048x2048":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/geth.jpg",300,203,false],"chromenews-featured":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/geth.jpg",300,203,false],"chromenews-large":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/geth.jpg",300,203,false],"chromenews-medium":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/02\/geth.jpg",300,203,false]},"author_info":{"info":["seandotau"]},"category_info":"<a href=\"https:\/\/www.talkcrypto.org\/blog\/category\/ethereum\/\" rel=\"category tag\">Ethereum<\/a>","tag_info":"Ethereum","comment_count":"0","_links":{"self":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts\/1824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/comments?post=1824"}],"version-history":[{"count":5,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts\/1824\/revisions"}],"predecessor-version":[{"id":1850,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts\/1824\/revisions\/1850"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/media\/1829"}],"wp:attachment":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/media?parent=1824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/categories?post=1824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/tags?post=1824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}