Connecting Geth to Metamask

Kacharlabhargav
3 min readOct 13, 2019

--

Metamask is a browser based Ethereum wallet that acts as a bridge between internet browsers, Ethereum, decentralized applications (DApps) built on Ethereum network. It is a browser extension which allows the interaction of web applications with the Ethereum blockchain without running a full Ethereum node.

Before getting to know on how to connect geth to Metamask lets setup Metamask in the browser. You can install this extension in Chrome, FireFox, Opera and Brave browser.

Installation:

Follow the below steps to install Metamask extension in chrome,

1. Run Chrome and go to Chrome Extension Website.

2. Search “MetaMask” to find the MetaMask extension offered by https://metamask.io.

3. Click “ADD TO CHROME” button to install it.

4. Check to the top right corner of the browser. You should see the MetaMask icon displayed on next to Chrome settings icon.

Creating an account in metamask:

1. Click on the MetaMask icon in the upper right corner to open the extension.

2. You will be asked to create a new password. Create a strong password and click Create.

3. Proceed by clicking Next, then accept Terms of Use.

4. Click Reveal secret words.

5. You will see a 12 words seed phrase. Save seed words as a file or copy them to a safe place and click Next.

6. Verify your secret phrase by selecting the previously generated phrase. When done, click Confirm.

Now an account is created in Metamask. You can get some free ether from any of the following websites. This ether does not represent any real value.

1. https://faucet.rinkeby.io

2. https://faucet.metamask.io

3. https://faucet.ropsten.be

Connecting to Metamask from private blockchain network:

You can install Geth by following the link.

To connect to MetaMask, you need to start the private Ethereum blockchain with an rpc flag. Try the following command in the terminal,

> geth — datadir ./data — networkid 2018 — rpc — rpccorsdomain “*” — rpcapi “admin,db,eth,miner,web3,net,personal,txpool” — allow-insecure-unlock

In Metamask, choose localhost.

If you get any error “something went wrong” then geth is not connecting to Metamask. Otherwise you can see the account details along with ether balance.

Sending ether from geth to Metamask account

Open geth in new terminal and type this command.

> geth attach ipc:/**path-to-geth.ipc**

This opens javascript console.

Send ether from geth account to Metamask with the below command,

eth.sendTransaction({from:eth.accounts[0], ***metamask account***,value: web3.toWei(4, “ether”)})

and start mining so that the transaction gets processed.

Miner.start(1)

The transferred ether gets reflected in your Metamask account after some time(longer than expected).

Importing geth account to Metamask

Now your geth and Metamask are connected to localhost:8545. You need to import the account in this localhost network.

You can import geth account to your Metamask.

  1. Click on Metamask extension, open the account menu in the top right and click on Import Account.

2. You can choose to import using Private Key and JSON File.

3. If you choose to use Json File type then you need to import KeyFile stored in your Keystore folder where your geth data is present.

4. Choose the KeyFile and enter the password you entered when you created this account in geth.

5. Click on Import button.

Now geth account is successfully imported into your Metamask.

You can make transaction by sending ether from this account from geth console or from Metamask.

Start mining in geth console so that this transaction gets processed. Now you can check the balance in your geth account same as balance in your Metamask account.

This way you can connect your private Ethereum blockchain network to Metamask.

Happy Learning.

--

--

Kacharlabhargav

Blockchain Developer | Ethereum | Hyperledger Fabric | GoLang | Software Developer