Using MetaMask to Interact with a Local Moonbeam Node

Derek Yoo
Moonbeam Network
Published in
5 min readJul 7, 2020

Moonbeam makes it possible to use the popular Ethereum-based extension in the Polkadot ecosystem

Moonbeam is an upcoming smart contract platform for the Polkadot network, currently in active development. Moonbeam is built using the Substrate blockchain development framework, which provides a core set of Ethereum compatibility modules.

Since Ethereum compatibility is core to Moonbeam’s value proposition, I thought it’d be helpful to give a quick demonstration of the type of functionality we mean when we say “Ethereum compatibility.”

This guide outlines steps to create and use a self-contained Moonbeam dev node to send tokens between Moonbeam accounts using MetaMask. The steps in the guide assume an Ubuntu 18.04 base OS.

Note: Since the project is currently in a pre-alpha stage, these instructions are subject to change. I’ll do my best to keep this article up-to-date.

First, Some Quick Background on Moonbeam

Moonbeam is a developer-oriented blockchain that strives to provide compatibility with the existing Ethereum developer tools and networks. It does this by providing a full EVM implementation, a Web3-compatible API, and bridges that connect Moonbeam to existing Ethereum networks. This allows developers to deploy existing Solidity smart contracts and DApp frontends to Moonbeam with minimal changes.

Moonbeam will also be a parachain on the Polkadot network. That means that it will get shared security from the Polkadot relay chain and will be able to integrate with other chains that are connected to Polkadot (once that functionality is available on Polkadot).

You can interact with Moonbeam in two ways: using Substrate RPC endpoints, or by using Web3-compatible RPC endpoints. The latter endpoints are currently being served from the same RPC server as the Substrate RPCs. In this tutorial, we will use the Web3 RPC endpoints to interact with Moonbeam.

Creating a Local Node

Start by downloading and building a Moonbeam node that will run in developer mode using the --dev flag.

Note: For people not familiar with Substrate, the --dev flag is a way you can run a Substrate-based node in a single node developer configuration for testing purposes. You can learn more about --dev in this Substrate tutorial.

The examples in this guide assume an Ubuntu 18.04-based environment and will need to be adapted accordingly for MacOS or Windows.

To install Moonbeam, clone and build this specific branch of the Moonbeam repo:

https://github.com/PureStake/moonbeam/tree/moonbeam-tutorials

Follow the installation instructions on that page to set up Rust, install Substrate, and clone the repo. Here is what the output from the clone action will look like:

Once you have cloned all the required repos, it’s time to build the node by running:

cargo build --release

The initial build will take a while, depending on your hardware. You should plan on 30 minutes. You may see warnings related to evm v0.16.1 and use of deprecated item `sc_service::AbstractService::spawn_essential_task` which can be ignored for purposes of this guide.

Here is what the tail end of the build output will look like:

Then you will want to run the node in dev mode using the following command:

./target/release/node-moonbeam --dev

You should see output that looks like the following and that shows blocks being produced:

Install MetaMask with Default Settings

Next, create a fresh and default MetaMask installation from the Chrome store, which is where you will import your dev account:

The details for the dev account for this example are:

Address: 0x6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b

Key: 99B3C12287537E38C90A9219D4CB074A89A16E9CDB20BF85728EBD97C343E342

On the import screen, select “Private Key” and paste in the key listed above:

You should end up with an imported “Account 2” that looks like this:

Connect to the Local Moonbeam Node

Now you’ll connect MetaMask to your locally running Moonbeam node.

Navigate to Settings -> Networks -> Add Network and fill in the following details:

Network Name: Moonbeam Dev
New RPC URL: http://127.0.0.1:9933
ChainID: 43

When you hit “save” and exit the network settings screen, MetaMask should be connected to the local Moonbeam dev node via its Web3 RPC, and you should see the Moonbeam dev account with a balance of 123456.123 ETH.

Initiating a Transfer

Let’s try sending some tokens with MetaMask.

For simplicity, you will transfer from your dev account to the default MetaMask account that came with your installation using the “Transfer between my accounts” option. Let’s transfer 100 tokens and leave all other settings at the default:

Once you submit, you will see the transaction in the “pending” state until it is confirmed like this:

Note that the Account 2 balance has been decreased by the sent amount + gas fees. Flipping over to Account 1, we see the 100 sent tokens have arrived:

Note: If you end up resetting your dev node using the Substrate purge-chain command, you will need to reset your MetaMask dev account using Settings -> Advanced -> Reset Account. This will clear the transaction history from your accounts and reset the nonce. Make sure you don’t erase anything you want to keep!

Next Tutorial:
Using the Remix IDE to Deploy a Solidity Smart Contract to Moonbeam

We Want to Hear From You

This is obviously a simple example, but it provides context for how you can start working with Moonbeam and how you can try out its Ethereum compatibility features. We are interested in hearing about your experience following the steps in this guide or your experience trying other Ethereum-based tools with Moonbeam. Feel free to join us in the Moonbeam Riot room here. We would love to hear your feedback on Moonbeam and answer any questions that you have.

View more tutorials like this on the Moonbeam documentation site:
https://docs.moonbeam.network/

Originally published at https://docs.moonbeam.network.

--

--