How to Create Your First dApp (Part 4) – Importing a node account into Metamask

In January 2022, I did a 30-day project on “Why Your Business Needs to Adapt to Blockchain”. This post is a part of it. To know what I covered, learned, and executed in the project, visit this page.

Up until now, I went through the fundamentals one needs to know to write a dApp, set up my environment and tools for writing the smart contract, and wrote the Greeter dApp. In this post, I show how a node account is imported into Metamask.

Importing a node account into Metamask

  • Take the private key, copy it → go into your metamask account → Account → Import Account, and paste the private key over there → Click on Import
  • Rename the account by clicking on the three dots → Account details → Edit pencil
  • hh-test01 is the account name.
  • It has 10000 Ethers.

Since the existing keys from Hardhat are known to everyone on the testnet, these keys cannot be used. So, I created an account that only my wallet knew.

  • Account → Create Account → Gave it a user name →recly-test02. It had 0Eth. It had joined the node that I had created. Since this account was not initially present in the node, it does not have any Ethers. Money can be transferred to this account. I did that using Metamask.
  • The public key is right below the Account name
  • I clicked on it to copy, then switched to hh-test01 account which had money, and clicked on send. It asked the public address of the receiver. I pasted the key that I had copied, entered the number of Eth to send.

The gas fee is the estimated transaction fee. In this case, it is 0.002603 ETH.

  • Then, confirm.

The transaction happened the first time I tried but failed when I tried again. 

You need to go to settings on Metamask → Advanced → reset the account to solve this problem. 

This doesn’t happen on the mainnet. Resetting is only required when we do localhost tests.

The transaction goes through after resetting the account. This is how the transaction appears on the Terminal:

The From and To include the public keys of recly-test01 and recly-test02 respectively.

Thus, I created an account on the node and got the contract compiled. Next, I had to deploy the contract on the node. I do that in Part 5.