Private Ethereum Client Communication with the MetaMask

The purpose of this article is solely educational.

In the previous article, I have discussed how you can use a Javascript console client to communicate with the Geth client, but now we will use MetaMask browser plugin for creating transactions instead of Javascript console.

1 – What is MetaMask

MetaMask provides an easy access to handle transaction requests through a better user experience. It also plays a role of vault to store your identities within your computer and act like an ETH crypto wallet. It is available as a plugin for browsers like chrome, brave, and Firefox.

MetaMask can connect to any Ethereum network, for instance, Ethereum’s MainNet and test-networks like Rinkeybay or Ropsten. It also allows connecting with any custom based private Ethereum node.

With its wallet functionality, it can store the identity and manage Ethers using local keys within the system regardless if they are real or fake/test Ethers. This client interface will help us to send or receive Ethers quickly without putting efforts on the command line scripts.

Make sure you will install this plugin before moving forward: Metamask. You can install this in Chrome / Firefox, or if you are using Brave, then it will come by default.

I will use the Brave browser to communicate with our private blockchain node. If you are interested in using the same browser, then you can download from brave.com.

2 – Open the MetaMask
Click your desired browser and then click the MetaMask plugin so you can see a beautiful fox face in a dialog which will follow your mouse pointer.

If this is your first time, then create a new account by giving a secret seed in the text field. Make sure you will save your secret seed information somewhere which can be retrieved later on. If you will lose this seed then there is a possibility exist that you can never be able to open your account again, in short, you will lose your Ethers regardless if they are real or fake. Your Ethers might remain on the network but you cannot use them anymore without your keys, therefore your keys supposed to be stored or save securely by yourself.

Now create a new password which you will use later to open the MetaMask.

3 – Overview About Different Networks and MetaMask
If you click the network drop-down list, then you will see all available networks from the Ethereum blockchain.

Mainnet will allow you to connect with the main official Ethereum network or in other words a production network. Here all transactions are real transactions; you can even create a new wallet through MetaMask. But be careful, since your wallet will remain in your computer so you must remember the secret seed.

Ropsten test network will allow you to connect on the official Ethereum’s testing network which is useful for testing transactions and to test new smart contracts before sending them on to the production. The consensus method on this network is Proof of Work (PoW), and this network reflects the same posture of the MainNet. But all transactions on this network are fake with testing accounts.

Rinkebay test network has the Proof of Authority (PoA) consensus method. Which means to conduct a transaction you must have to reveal your identity. In Rinkebay, you can get testing Ethers by requesting from the network and by sharing a particular link through your identity through any social media account. Since this network is PoA, so it is immune to the SPAM, unlike Ropsten.

4 – Changing the Network
An important note related to the MetaMask, if you create an account and you are using Ropsten network, but later you switch to the Main network then you will find no Ether in your wallet which you had on the Ropsten network. But if you change the wallet back to the Ropsten, then it will start showing you your test Ethers.

Your wallet remains same by the account id or hash, but the wallet Ethers will be based on the network type and its previous history. Maybe Metamask will fix this issue in future but at the moment if you are switching networks then don’t get shocked to see zero balance.

I will discuss these testing networks in my another article in more detail since the scope of this article is to show you how you can connect MetaMask with your private network.

5 – Setup Custom RPC Network

Click the Custom RPC and then add your IPC endpoint address. If you remember when we ran the first Ethereum node, then we saw an RPC address http://127.0.0.1:8545

The same address you must enter inside the MetaMask Custom RPC Setting field. Make sure to add the port 8545 along with the same URL.

Click Save and then go to the network list where you will find “Localhost 8545” or “127.0.0.1:8545” as a new item. Now click the new network item and wait for few seconds then you will see yourself connected on the network. If you face any issue like if the loading does not get finish then be sure your Ethereum Geth node is running.

6 – Login or Signup on the MetaMask
It is vital that you must have an account for the MetaMask, so signup a new user by entering a new password and then make sure to save the random seed somewhere offline. Now login to the MetaMask and you will see its small tiny dashboard.

Blockchains MetaMask Login
7 – Import existing Accounts
We have to import our existing accounts which we had created previously. Just click the user icon on the top right, and then select “Import Accounts”.

MetaMask Import Account
Here you will see “select type” field, therefore select the JSON File option. This option will help us to import the keystore files and allow us to treat them as accounts.

Browse the file, and select the keystore user file. Now you have to enter the relevant password to unlock the account and import it completely.

MetaMask JSON Option
After the import, you will see some balance in the account which you had earned through previous transactions which were demonstrated in the last article. You can see by default a name was given to this account as “Account 5” which you can rename to anything. The amount showed in this account is 99.999 ETH.

Now repeat the same import process for the other two accounts. You will find all accounts in your user’s drop-down list as below. (I have changed the account names to PvtNodeAcc1 , PvtNodeAcc2 and PvtNodeCoinAcc). Now you can easily perform transactions like send and receive ETH on your private node without using the Web3JS Console.

8 – Send Some Ethers to Another Account
I am sure you must be asking why we should use MetaMask when we have Web3JS, so the answer is “for a rapid development” or “rapid testing” or “for better user experience”. It is far better to use this great interactive MetaMask plugin which will remove the efforts in writing manual scripts and it will obviously save your time.

MetaMask Transactions
Try to play with the interface and send or receive ETH from these accounts. This will clear your concepts how MetaMask has eased your testing. Especially if you are thinking to create your own coin on the top of ETH, then this MetaMask is your life saver in your testing journey.

Transaction Mining Data

As you can see in the above snapshot, Geth console is showing how a new transaction has been processed, look at the address and the recipient.

So in this article, we have learned how to connect private Ethereum node with the MetaMask, and Metamask has given us a great GUI to send and receive Ethers between different accounts.

In my next article, I will discuss the Ganache an Ethereum Simulator.