Skip to content

An Ethereum-compatible smart contract parachain on Polkadot

License

Notifications You must be signed in to change notification settings

floppyssh/moonbeam

 
 

Repository files navigation

moonbeam

Tests

Run an Ethereum compatible parachain (and blockchain for now, until parachains are more stable) based on Substrate.

See moonbeam.network for the moonbeam blockchain description.
See www.substrate.io for substrate information.

Install (linux)

Get the code

Get the tutorial specific tag of the PureStake/Moonbeam repo:

git clone -b tutorial-v3 https://github.com/PureStake/moonbeam
cd moonbeam

Setting up enviroment

Install Substrate pre-requisites (including Rust):

curl https://getsubstrate.io -sSf | bash -s -- --fast

Run the initialization script, which checks the correct rust nightly version and adds the wasm32-unknown-unknown target to that specific version:

./scripts/init.sh

Build the Moonbeam Node

Build the corresponding binary file:

cargo build --release

The first build takes a long time, as it compiles all the necessary libraries.

If a cargo not found error appears in the terminal, manually add Rust to your system path (or restart your system):

source $HOME/.cargo/env

Run a Development Node

Moonbeam is designed to be a parachain on the Polkadot network. For testing your contracts locally, spinning up a full relay-para network is a lot of overhead.

A simpler solution is to run the --dev node, a simple node that is not backed by any relay chain, but still runs the Moonbeam runtime logic.

./target/release/moonbase-standalone --dev

Docker image

An alternative to building locally is to use docker to run a pre-build binary. The only requirement is to have Docker installed.

# Pull the docker image
docker pull purestake/moonbase-parachain-testnet:latest

# Start a dev node
docker run --rm --network host purestake/moonbase /moonbase/moonbase-standalone --dev

Chain IDs

The Ethereum specification described a numeric Chain Id. The Moonbeam mainnet Chain Id will be 1284 because it takes 1284 milliseconds for a moonbeam to reach Earth.

Moonbeam nodes support multiple public chains and testnets, with the following Chain Ids.

Network Description Chain ID
Local Parachain TestNet 1280
Local Development TestNet 1281
Reserved for other TestNets 1282 - 1283
Moonbeam (Polkadot) 1284
Moonriver (Kusama) 1285
Moonrock (Rococo) 1286
Moonbase Alpha TestNet 1287
Reserved for other public networks 1288 - 1289

Runtime Architecture

The Moonbeam Runtime is built using FRAME and consists of pallets from substrate, frontier, cumulus, and pallets/.

From substrate:

  • Balances: Tracks GLMR token balances
  • Sudo: Allows a privileged account to make arbitrary runtime changes - will be removed before launch
  • Timestamp: On-Chain notion of time
  • Transaction Payment: Transaction payment (fee) management
  • Randomness Collective Flip: A (mock) onchain randomness beacon. Will be replaced by parachain randomness by mainnet.

From frontier:

  • EVM: Encapsulates execution logic for an Ethereum Virtual Machine
  • Ethereum: Ethereum-style data encoding and access for the EVM.

From cumulus:

  • ParachainUpgrade: A helper to perform runtime upgrades on parachains
  • ParachainInfo: A place to store parachain-relevant constants like parachain id

The following pallets are stored in pallets/. They are designed for Moonbeam's specific requirements:

  • Ethereum Chain Id: A place to store the chain id for each Moonbeam network
  • Author Inherent: Allows block authors to include their identity in a block via an inherent
  • Stake: Minimal staking pallet that implements ordered validator selection by total amount at stake

Tests

Tests are run with the following command:

cargo test --verbose

This github repository is also linked to Gitlab CI

Contribute

Code style

Moonbeam is following the Substrate code style
We provide a .editorconfig (compatible with VSCode using RLS)

About

An Ethereum-compatible smart contract parachain on Polkadot

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 50.8%
  • TypeScript 42.2%
  • Shell 5.3%
  • Other 1.7%