C 342: MetaMask with Local Testnet (10 pts.)

What You Need

Purpose

To connect the MetaMask wallet to your local Ethereum testnet.

Verifying that geth is Running

On your Linux machine, with geth running, execute this command:
ss -pant
You should see geth listening on port 8545, as shown below.

If you do not see geth listening, refer to project C 333 to see how to start it.

Adding a Socat Forwarder

geth is listening on the localhost address, which would work if you are running Chrome and MetaMask on the same machine. But I am using a headless Debian server and running Chrome on the host MacOS. So I need to forward that port to an externally visible IP address.

On your Linux machine, with geth running, execute these commands:

sudo apt update
sudo apt install socat -y
socat TCP-LISTEN:18545,fork TCP:127.0.0.1:8545 &
ss -pant
You should see socat listening on 0.0.0.0:18545, as shown below.

Finding the Linux Server's IP Address

On your Linux machine,execute this command:
ip a
Find your IP address and make a note of it.

Finding your Chain ID

On your Linux machine,execute this command:
curl  -H "Content-Type: application/json" -X POST \
--data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' \
http://localhost:8545
Find your chainID. In the image below, it is 0xa in hexadecimal, or 10.

Connecting with MetaMask

On your host machine, launch Chrome and launch MetaMask.

At the top center, click "Ropsten Test Network" and click "Custom RPC", as shown below.

Enter these values, as shown below, replacing the IP address with the address of your Linux server:

Click Save.

Close the Settings box.

Finding your Private Key JSON File

On your Linux server, execute these commands:
cd
ls .ethereum/keystore
You see the name of your private key file, as shown below.

On your Linux server, use cat to print out that file, as shown below.

Higlight the JSON code, as shown below, and copy it.

On your host machine, create a text file, paste the JSON into it, and save it.

Importing your Account

On your host machine, in Chrome, if the MetaMask page is not maximized, at the top right, click the three-dot icon and click "Expand view". MetaMask doesn't work properly unless it is filling a Chrome tab.

A the top right of the MetaMask page, the network name is now local, and your balance is 0 ETH, because the account in your wallet is not the account you used to mine on your local testnet blockchain.

At the top right. click the circular icon and click "Import Account".

Select a Type of "JSON File". Click the "Choose File" button and open the file you created.

Enter the password you specified when creating the account in project C 333, as shown below.

Click the Import button.

You see a frozen page, as shown below.

The import is working, but it is incredibly slow, due to a known bug in MetaMask.

Wait for it to finish. It may take up to 20 minutes.

When it finishes, your account will connect, and you will have a very large amount of ETH, as shown below.

Sending Ether to Yourself

At the top center, click your Account number.

A context box pops up saying Copied.

In the center of your screen, click the blue Send button.

Paste in the address, and enter an Amount of "1000 ETH", as shown below.

Click Next. Click Confirm.

Wait a few seconds, while the transaction finishes.

In the lower portion of the window, click the Activity tab, as shown below.

C 342.1: Activity Log (10 pts)

In the lower left of the window, click Send.

The flag is covered by a green rectangle in the image below.

References

Connecting MyEtherWallet, Mist, and MetaMask to Your Private Blockchain

Posted 5-14-2021