Moonbeam: The EVM of Polkadot
Deploying and onboarding users to Moonbeam or Moonriver
We've covered several Layer 2 sidechains before:
But Moonbeam is unique since it's a parachain of the Polkadot ecosystem. It only just launched which means you are now able to deploy smart contracts to the chain. Being able to deploy EVM contracts to the Polkadot world comes with unique features.

What is Moonbeam?
Moonbeam is a Polkadot parachain. Rather than regular sidechains, a parachain in Polkadot has unique security benefits. It can take advantage of the Polkadot chain's security. This shared security mechanism can greatly decrease the risk for 51% attacks like happened for Ethereum Classic attack on January 10. Parachains can also make use of Cross-Consensus Message Format (XCM) which allows to send messages from one parachain to another one. And yes you can use tokens transferred via XCM in your smart contracts!
And you can send regular Ethereum transactions to Moonbeam. Moonbeam has implemented a fully functioning EVM as part of a Polkadot parachain. The EVM is fully functioning with most precompiles and all opcodes available. But since Moonbeam itself is a Proof of Stake chain, some opcodes have no meaning in Moonbeam. If you are reading things like the block hash or difficulty, it will only return some default values.
The available precompiles and additionally deployed helper contracts can be found here. In particular Moonbeam specific features include:
- Parachain Staking: You can interact with the parachain staking directly by (un-)-delegating and retrieving rewards.
- Crowdloan Rewards: You can retrieve crowdloan information as well as claim rewards.
- Wrapped GLMR as ERC-20: 0xAcc15dC74880C9944775448304B263D191c6077F
All code for Moonbeam can be found here. And block explorers either with Moonbeam Blockscout or Moonscan.
Why choose Moonbeam?
Since Moonbeam is a Polkadot parachain, deploying smart contracts to it will have a much higher security than deploying to other sidechains. The Polkadot relay chain has a very large market cap currently being in the Top 10 of all chains. And with Moonbeam you can take full advantage of the speed, Proof of Stake and low gas fees without having to compromise on the security aspect.
And you can make use of new features!
Parachain Staking
You can directly access staking features using the ParachainStaking interface contract at address 0x0000000000000000000000000000000000000800.
This will allow you to delegate funds directly to the Moonbeam parachain staking from Proof of Stake within your smart contract.
- You can use the
delegatefunction to start a delegation to parachain node (called collator). - You can use
schedule_leave_delegatorsto stop a delegation.
There are a few other functions in the interface which you can see here, but the ones on the right will be the most important ones.
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.8.0;
interface ParachainStaking {
function is_delegator(
address delegator
) external view returns (bool);
function is_candidate(
address candidate
) external view returns (bool);
function delegate(
address candidate,
uint256 amount,
uint256 candidateDelegationCount,
uint256 delegatorDelegationCount
) external;
function schedule_leave_delegators() external;
}Crowdloan Rewards
And you can also access crowdloan rewards to get info or to claim rewards for any crowdloan participant. The interface is available at address 0x0000000000000000000000000000000000000801.
If you're wondering what the heck is a crowdloan? The short answer is there is a limited amount of parachain slots available since every parachain increases the computational complexity of nodes in the Polkadot chain. That's why there are auctions for the slots as 2-year leasings. Whoever bids the most DOT will receive the slot for two years, while having their DOT locked during this time. A crowdloan then is a mechanism that most projects are using to collectively use DOT together and participants will receive the project's token as reward.
In the case of Moonbeam crowdloan participants received 30% initially and the rest is vested of a two year time with rewards being able to be claimed continuously.
You can see past, current and future auctions here. As you can see Moonbeam actually won the second auction right after Acala.
interface CrowdloanRewards {
function is_contributor(
address contributor
) external view returns (bool);
function reward_info(
address contributor
) external view returns (uint256, uint256);
function claim() external;
function update_reward_address(
address new_address
) external;
}XCM Tokens
Since Moonbeam is a parachain in Polkadot, you can make use of the cross-chain transfers. Inside your contracts you cannot directly transfer send XCM messages, because the EVM has no functionality for this. (although I imagine the Moonbeam EVM could get an upgrade to support this later?)
But you can still use cross-chain tokens. Moonbeam makes them automatically available as fully compatible ERC-20 tokens. If you wanted to do cross-chain transfers yourself, you will need to use the Moonbeam Substrate API. What is Substrate you may ask?
Substrate is a framework for developing your own blockchain as part of the Polkadot ecosystem. So Moonbeam itself was developed using this framework. And while Moonbeam provides an abstraction layer to be EVM compatible, under the hood the blockchain is managed in Substrate. So to use native Substrate features, you need to move out of the EVM abstraction. You can find a block explorer for the Substrate part of Moonbeam here.
Moonbeam vs. Moonriver: Which one to choose?
One unique feature of the Polkadot ecosystem is that they have a so-called canary chain: Kusama. It's the same chain as Polkadot except that they are more experimental (hence the name canary) by doing everything faster. For example governance time is shorter, unstaking period is shorter and the parachain auctions for Kusama started already half a year ago. And that's why some projects have two parachains, one on Kusama and one on Polkadot. In the case of Moonbeam, there is also the Moonriver parachain with the connection to Kusama. So which one should you use?
Moonriver will be the faster upgrading, more experimental chain with less security. For your own Dapp on Moonbeam you have three options:
- Deploy only to Moonbeam: higher security, more stable, longer time for upgrades
- Deploy only to Moonriver: lower security, less stable, faster time for upgrades
- Deploy to Moonbeam and Moonriver: highest security, since you will have your own canary Dapp this way, but more effort to maintain
Which option you choose is up to you. If you're unsure, you're probably best to deploy only to Moonbeam since it gives you high security without extra work.

Moonbeam Ecosystem
There is a large ecosystem evolving around Moonbeam. You can find many tools and projects currently working towards integrating Moonbeam. Many are at the time of writing still work in progress for Moonbeam. For example the Band and Chainlink oracles are not yet available, although Chainlink is available for Moonriver.
You can already use The Graph on Moonbeam. Check out my tutorial how to use it here. It's the best tool for querying blockchain data in your Dapp's frontend.
And if you're looking to integrate a DEX in your contracts like Uniswap, Solarflare is exactly that. If you want to integrate it, my previous Uniswap 2 tutorial should work just fine.

How to deploy to Moonbeam
Deploying to Moonbeam is very simple. If you're using Truffle or Hardhat, simply add the network configuration like this:
moonbeam: {
provider: () => new HDWalletProvider(mnemonic, 'https://rpc.api.moonbeam.network'),
network_id: 1284,
},
},
moonriver: {
provider: () => new HDWalletProvider(mnemonic, 'https://rpc.api.moonriver.network'),
network_id: 1285,
},
},
moonbase-alpha: {
provider: () => new HDWalletProvider(mnemonic, 'https://rpc.api.moonbase.moonbeam.network'),
network_id: 1287,
},
},You'll also need funds in the chain of course. For the testnet you can use the faucet via the faucet channel at the Moonbeam Discord. For Moonbeam and Moonriver funds, you'll need to purchase those on an exchange.
How to onboard users to your Moonbeam Dapp
1. Choice of wallet
These days you have much more than just MetaMask as possible wallets to support available. Take a look at Yearn Finance for example. They are supporting 11 different wallets alone at the time of this writing.


2. MetaMask example live in action
We'll focus on MetaMask as the biggest wallet with the most features. With MetaMask you can nowadays actually request to connect directly to a custom network.
If you want to see this live, just go to the Moonbeam docs. Unless you already have Moonbeam Network added, it will request to add this network.
3. How to add Moonbeam automatically for users
You can see on the right how to add the Moonbeam automatically to the wallet for the user. This will show the popup you see above. If the user confirms, the network is added and automatically switched to.
This is all thanks to EIP-3085 with the new RPC method wallet_addEthereumChain . See also the MetaMask docs here.
const params = [{
"chainId": "1284",
// Moonriver: "chainId": "1285",
// Testnet: "chainId": "1287",
"chainName": "Moonbeam",
// or "Moonriver" or "Moonbase Alpha"
"rpcUrls": [
"https://rpc.api.moonbeam.network"
// or "https://rpc.moonriver.moonbeam.network"
// or "https://rpc.api.moonbase.moonbeam.network"
],
"nativeCurrency": {
"name": "Glimmer", // or Moonriver or Dev
"symbol": "GLMR", // or MOVR or DEV
"decimals": 18
},
"blockExplorerUrls": [
"https://moonscan.io"
// or "https://moonriver.moonscan.io/"
// or "https://moonbase.moonscan.io/"
]
}]
try {
await ethereum.request({
method: 'wallet_addEthereumChain',
params,
})
} catch (error) {
// something failed, e.g., user denied request
}Solidity Developer
More great blog posts from Markus Waas
How to use ChatGPT with Solidity
Using the Solidity Scholar and other GPT tips
How to integrate Uniswap 4 and create custom hooks
Let's dive into Uniswap v4's new features and integration
How to integrate Wormhole in your smart contracts
Entering a New Era of Blockchain Interoperability
Solidity Deep Dive: New Opcode 'Prevrandao'
All you need to know about the latest opcode addition
How Ethereum scales with Arbitrum Nitro and how to use it
A blockchain on a blockchain deep dive
The Ultimate Merkle Tree Guide in Solidity
Everything you need to know about Merkle trees and their future
The New Decentralized The Graph Network
What are the new features and how to use it
zkSync Guide - The future of Ethereum scaling
How the zero-knowledge tech works and how to use it
Exploring the Openzeppelin CrossChain Functionality
What is the new CrossChain support and how can you use it.
Deploying Solidity Contracts in Hedera
What is Hedera and how can you use it.
Writing ERC-20 Tests in Solidity with Foundry
Blazing fast tests, no more BigNumber.js, only Solidity
ERC-4626: Extending ERC-20 for Interest Management
How the newly finalized standard works and can help you with Defi
Advancing the NFT standard: ERC721-Permit
And how to avoid the two step approve + transferFrom with ERC721-Permit (EIP-4494)
Advanced MultiSwap: How to better arbitrage with Solidity
Making multiple swaps across different decentralized exchanges in a single transaction
Deploying Solidity Smart Contracts to Solana
What is Solana and how can you deploy Solidity smart contracts to it?
Smock 2: The powerful mocking tool for Hardhat
Features of smock v2 and how to use them with examples
How to deploy on Evmos: The first EVM chain on Cosmos
Deploying and onboarding users to Evmos
EIP-2535: A standard for organizing and upgrading a modular smart contract system.
Multi-Facet Proxies for full control over your upgrades
MultiSwap: How to arbitrage with Solidity
Making multiple swaps across different decentralized exchanges in a single transaction
The latest tech for scaling your contracts: Optimism
How the blockchain on a blockchain works and how to use it
Ultimate Performance: The Aurora Layer2 Network
Deploying and onboarding users to the Aurora Network powered by NEAR Protocol
What is ecrecover in Solidity?
A dive into the waters of signatures for smart contracts
How to use Binance Smart Chain in your Dapp
Deploying and onboarding users to the Binance Smart Chain (BSC)
Using the new Uniswap v3 in your contracts
What's new in Uniswap v3 and how to integrate Uniswap v3
What's coming in the London Hardfork?
Looking at all the details of the upcoming fork
Welcome to the Matrix of blockchain
How to get alerted *before* getting hacked and prevent it
The Ultimate Ethereum Mainnet Deployment Guide
All you need to know to deploy to the Ethereum mainnet
SushiSwap Explained!
Looking at the implementation details of SushiSwap
Solidity Fast Track 2: Continue Learning Solidity Fast
Continuing to learn Solidity fast with the advanced basics
What's coming in the Berlin Hardfork?
Looking at all the details of the upcoming fork
Using 1inch ChiGas tokens to reduce transaction costs
What are gas tokens and example usage for Uniswap v2
Openzeppelin Contracts v4 in Review
Taking a look at the new Openzeppelin v4 Release
EIP-3156: Creating a standard for Flash Loans
A new standard for flash loans unifying the interface + wrappers for existing ecosystems
Tornado.cash: A story of anonymity and zk-SNARKs
What is Tornado.cash, how to use it and the future
High Stakes Roulette on Ethereum
Learn by Example: Building a secure High Stakes Roulette
How to implement generalized meta transactions
We'll explore a powerful design for meta transactions based on 0x
Utilizing Bitmaps to dramatically save on Gas
A simple pattern which can save you a lot of money
Using the new Uniswap v2 as oracle in your contracts
How does the Uniswap v2 oracle function and how to integrate with it
Smock: The powerful mocking tool for Hardhat
Features of smock and how to use them with examples
How to build and use ERC-721 tokens in 2021
An intro for devs to the uniquely identifying token standard and its future
Trustless token management with Set Protocol
How to integrate token sets in your contracts
Exploring the new Solidity 0.8 Release
And how to upgrade your contracts to Solidity 0.8
How to build and use ERC-1155 tokens
An intro to the new standard for having many tokens in one
Leveraging the power of Bitcoins with RSK
Learn how RSK works and how to deploy your smart contracts to it
Solidity Fast Track: Learn Solidity Fast
'Learn X in Y minutes' this time with X = Solidity 0.7 and Y = 20
Sourcify: The future of a Decentralized Etherscan
Learn how to use the new Sourcify infrastructure today
Integrating the 0x API into your contracts
How to automatically get the best prices via 0x
How to build and use ERC-777 tokens
An intro to the new upgraded standard for ERC-20 tokens
COMP Governance Explained
How Compound's Decentralized Governance is working under the hood
How to prevent stuck tokens in contracts
And other use cases for the popular EIP-165
Understanding the World of Automated Smart Contract Analyzers
What are the best tools today and how can you use them?
A Long Way To Go: On Gasless Tokens and ERC20-Permit
And how to avoid the two step approve + transferFrom with ERC20-Permit (EIP-2612)!
Smart Contract Testing with Waffle 3
What are the features of Waffle and how to use them.
How to use xDai in your Dapp
Deploying and onboarding users to xDai to avoid the high gas costs
Stack Too Deep
Three words of horror
Integrating the new Chainlink contracts
How to use the new price feeder oracles
TheGraph: Fixing the Web3 data querying
Why we need TheGraph and how to use it
Adding Typescript to Truffle and Buidler
How to use TypeChain to utilize the powers of Typescript in your project
Integrating Balancer in your contracts
What is Balancer and how to use it
Navigating the pitfalls of securely interacting with ERC20 tokens
Figuring out how to securely interact might be harder than you think
Why you should automatically generate interests from user funds
How to integrate Aave and similar systems in your contracts
How to use Polygon (Matic) in your Dapp
Deploying and onboarding users to Polygon to avoid the high gas costs
Migrating from Truffle to Buidler
And why you should probably keep both.
Contract factories and clones
How to deploy contracts within contracts as easily and gas-efficient as possible
How to use IPFS in your Dapp?
Using the interplanetary file system in your frontend and contracts
Downsizing contracts to fight the contract size limit
What can you do to prevent your contracts from getting too large?
Using EXTCODEHASH to secure your systems
How to safely integrate anyone's smart contract
Using the new Uniswap v2 in your contracts
What's new in Uniswap v2 and how to integrate Uniswap v2
Solidity and Truffle Continuous Integration Setup
How to setup Travis or Circle CI for Truffle testing along with useful plugins.
Upcoming Devcon 2021 and other events
The Ethereum Foundation just announced the next Devcon in 2021 in Colombia
The Year of the 20: Creating an ERC20 in 2020
How to use the latest and best tools to create an ERC-20 token contract
How to get a Solidity developer job?
There are many ways to get a Solidity job and it might be easier than you think!
Design Pattern Solidity: Mock contracts for testing
Why you should make fun of your contracts
Kickstart your Dapp frontend development with create-eth-app
An overview on how to use the app and its features
The big picture of Solidity and Blockchain development in 2020
Overview of the most important technologies, services and tools that you need to know
Design Pattern Solidity: Free up unused storage
Why you should clean up after yourself
How to setup Solidity Developer Environment on Windows
What you need to know about developing on Windows
Avoiding out of gas for Truffle tests
How you do not have to worry about gas in tests anymore
Design Pattern Solidity: Stages
How you can design stages in your contract
Web3 1.2.5: Revert reason strings
How to use the new feature
Gaining back control of the internet
How Ocelot is decentralizing cloud computing
Devcon 5 - Review
Impressions from the conference
Devcon 5 - Information, Events, Links, Telegram
What you need to know
Design Pattern Solidity: Off-chain beats on-chain
Why you should do as much as possible off-chain
Design Pattern Solidity: Initialize Contract after Deployment
How to use the Initializable pattern
Consensys Blockchain Jobs Report
What the current blockchain job market looks like
Provable — Randomness Oracle
How the Oraclize random number generator works
Solidity Design Patterns: Multiply before Dividing
Why the correct order matters!
Devcon 5 Applications closing in one week
Devcon 5 Applications closing
Randomness and the Blockchain
How to achieve secure randomness for Solidity smart contracts?