This tutorial will connect your local geth ethereum private blockchain to Metamask using json file or private keys and perform transactions(send and receive ethers within the network).
To create a geth ethereum private blockchain, follow the below article: https://asha-singh7558.medium.com/setup-geth-ethereum-private-network-3806ef7fbe42
Now that we have our local blockchain, it is running on “http://localhost:8545”.
MetaMask is an extension for accessing Ethereum enabled distributed applications, or “Dapps” in your browser. You can refer the official documentation to setup a metamask wallet: https://metamask.io/
Now that you have metamask wallet and geth blockchain running,
Step1 is to setup the network in metmask.
Click on Settings => Networks
Click on ‘Add a network’ and create the network with the rpc URL and chain Id.
Now, the connection setup is done.
Step 2 is to import the accounts from the geth network to the metamask. There are 2 ways to import accounts, 1st is to import using json file & password and 2nd is to import using private key.
We have two accounts in geth private blockchain and let’s import via both ways.
You can find the details of the accounts in the keystore directory:
Import Accounts in metamask:
- Import using json file. Click on ‘Import Account’ and select Type as ‘JSON File’ and select the keystore file and pass the password for the keystore file. And click on Import, it will import the account.
2. Import using ‘private key’. For this, we need to extract the private key from keystore file and this can be achieved by installing the web3 CLI.
Command: curl -LSs https://raw.githubusercontent.com/gochain/web3/master/install.sh | sh
Command to extract the private key from keystore file : web3 account extract — keyfile <file-path> — password <password>
In metamask, click on ‘Import Account’ and select Type as ‘Private Key’ and pass the private key. And click on Import, it will import the account.
Accounts are successfully imported in Metamask.
In Account, click on send and select the other account and the ethers and confirm the transaction.
In the geth network, you can see the details of the transaction submitted.
Done!!!!!!!!!!!!!!! You have successfully completed the tutorial.
Happy Learning!!