polkadot Compatible with Moonbeam of Ethereum Project in Taifang

Keywords: Blockchain Ethereum

brief introduction

Ethereum-compatible parallel chains built with Substrate. It references frontier's code.
Moonbeam is a developer-oriented block chain dedicated to providing compatibility with existing Ethernet developer tool chains and networks. It does this by providing a complete EVM implementation, a Web3-compatible API, and a bridge connecting the Moonbeam to the existing Ethernet network. This allows developers to deploy existing Solidity smart contracts and DApp front-end to Moonbeam with minimal changes.
Moonbeam will also become a parallel chain on the Polkadot network. This means that it will gain shared security from the Polkadot relay chain and be able to integrate with other chains connected to Polkadot.

deploy

  1. clone Source
git clone -b v0.13.2 https://github.com/PureStake/moonbeam
cd moonbeam
  1. Compile
cargo build --release

3. Run

./target/release/moonbeam --dev

You should see the output shown below, showing the idle state of the block waiting to be generated:

2021-10-20 15:33:19 Running in --dev mode, RPC CORS has been disabled.    
2021-10-20 15:33:19 Moonbeam Parachain Collator    
2021-10-20 15:33:19 ✌️  version 0.13.2-aa753d26d-x86_64-macos    
2021-10-20 15:33:19 ❤️  by PureStake, 2019-2021    
2021-10-20 15:33:19 📋 Chain specification: Moonbase Development Testnet    
2021-10-20 15:33:19 🏷 Node name: sedate-monkey-5935    
2021-10-20 15:33:19 👤 Role: AUTHORITY    
2021-10-20 15:33:19 💾 Database: RocksDb at /Users/kuangqiling/Library/Application Support/moonbeam/chains/moonbase_dev/db    
2021-10-20 15:33:19 ⛓  Native runtime: moonbase-800 (moonbase-0.tx2.au3)    
2021-10-20 15:33:19 Using default protocol ID "sup" because none is configured in the chain specs    
2021-10-20 15:33:19 🏷 Local node identity is: 12D3KooWH1WRAm4QNKfDEjRWNnqP7Uma95FrCrX4sZy7ncJc3XoR    
2021-10-20 15:33:21 📦 Highest known block at #11    
2021-10-20 15:33:21 〽️ Prometheus exporter started at 127.0.0.1:9615    
2021-10-20 15:33:21 Listening for new connections on 127.0.0.1:9944.    
2021-10-20 15:33:21 Development Service Ready    
2021-10-20 15:33:26 💤 Idle (0 peers), best: #11 (0xb9a4...0629), finalized #0 (0x2b22...a518),

Connect polkadot-js

The development node is a Substrate-based node, so you can interact with it using standard Substrate tools. The two RPC endpoints provided are:

  • HTTP: http://127.0.0.1:9933
  • WS: ws://127.0.0.1:9944
    First connect to it using the Polkadot.js application. Open browser: https://polkadot.js.org/apps/#/explorer . This opens Polkadot.js Apps, which automatically connects to Polkadot MainNet.

    Click the upper left corner to open the menu to configure the network, and navigate down to open the development submenu. There, you need to switch the Local Node option, which points the Polkadot.js application to ws://127.0.0.1:9944.Next, select the Switch button, and the site should be connected to your Moonbeam development node.

    After connecting to the Polkadot.js application, you will see the Moonbeam development node waiting for the transaction to arrive to start building blocks.

Use metamask to view account status

  1. configure network
  2. Import Key
    Development Node with 10 Funded Development Accounts
    Mnemonic:
bottom drive obey lake curtain smoke basket hold race lonely fit walk
Alith:

Public Address: 0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac
Private Key: 0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133
Baltathar:

Public Address: 0x3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0
Private Key: 0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b
Charleth:

Public Address: 0x798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc
Private Key: 0x0b6e18cafb6ed99687ec547bd28139cafdd2bffe70e6b688025de6b445aa5c5b
Dorothy:

Public Address: 0x773539d4Ac0e786233D90A233654ccEE26a613D9
Private Key: 0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68
Ethan:

Public Address: 0xFf64d3F6efE2317EE2807d223a0Bdc4c0c49dfDB
Private Key: 0x7dce9bc8babb68fec1409be38c8e1a52650206a7ed90ff956ae8a6d15eeaaef4
Faith:

Public Address: 0xC0F0f4ab324C46e55D02D0033343B4Be8A55532d
Private Key: 0xb9d2ea9a615f3165812e8d44de0d24da9bbd164b65c4f0573e1ce2c8dbd9c8df
Goliath:

Public Address: 0x7BF369283338E12C90514468aa3868A551AB2929
Private Key: 0x96b8a38e12e1a31dee1eab2fffdf9d9990045f5b37e44d8cc27766ef294acf18
Heath:

Public Address: 0x931f3600a299fd9B24cEfB3BfF79388D19804BeA
Private Key: 0x0d6dcaaef49272a5411896be8ad16c01c35d6f8c18873387b71fbc734759b0ab
Ida:

Public Address: 0xC41C5F1123ECCd5ce233578B2e7ebd5693869d73
Private Key: 0x4c42532034540267bf568198ccec4cb822a025da542861fcb146a5fab6433ff8
Judith:

Public Address: 0x2898FE7a42Be376C8BC7AF536A940F7Fd5aDd423
Private Key: 0x94c49300a58d576011096bcb006aa06f5a91b34b4383891e8029c21dc39fbb8b

Import one of the Private Key s to metamask

  1. We can see that the balance is displayed properly

Deploy smart contracts using remix

  1. open https://remix.ethereum.org/ And open the example Owner.sol
  2. Compile
  3. Instead, switch to deploying tab s
    Fill in rpc interface address
  4. Open metamsk to select a connection account and you will see the account and balance in the deploy interface

    5. Fill in gas limit click deployment
  5. The metamask interface opens automatically, click OK
  6. console displays the deployment status
  7. Open Block 12 in polkadot.js to view transactions
  8. evm log shows the contract address
  9. Enter the contract address in the deploy interface and click At address
  10. Click to expand. Here's how the contract works.
  11. Click getOwner to get the current Owner
  12. Enter another account address in address newOwner and click changeOwner
  13. This opens metamask and clicks OK again, which completes a contract call
  14. Click getOwner again, and a new address will be displayed indicating that the contract method call was successful

Publish a token using truffle

Truffle v5.4.15 (core: 5.4.15)
Solidity - ^0.7.0 (solc-js)
Node v15.12.0
Web3.js v1.5.3

  1. clone Project
git clone https://github.com/PureStake/moonbeam-truffle-box
cd moonbeam-truffle-box
  1. Installation Dependency
yarn install
  1. Modify the configuration file truffle-config.js
    Replace your private key
const HDWalletProvider = require('@truffle/hdwallet-provider');
// Moonbeam Development Node Private Key
const privateKeyDev =
   '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133';
//...
module.exports = {
   networks: {
      dev: {
         provider: () => {
            ...
            return new HDWalletProvider(privateKeyDev, 'http://127.0.0.1:9933')
         },
         network_id: 1281,  // 0x501 in hex,
      },
      //...
   },
   plugins: ['moonbeam-truffle-plugin']
};
  1. truffle box has an erc-20 currency contract
    contracts/MyToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.5;

// Import OpenZeppelin Contract
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

// This ERC-20 contract mints the specified amount of tokens to the contract creator.
contract MyToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("MyToken", "MYTOK") 
    {
        _mint(msg.sender, initialSupply);
    }
}
  1. Compile
  2. deploy
truffle migrate --network dev

Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
> Everything is up to date, there is nothing to compile.



Starting migrations...
======================
> Network name:    'dev'
> Network id:      1281
> Block gas limit: 15000000 (0xe4e1c0)


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0xeb0b1dca071fa9293a3000a98d2ab54587d00888cc0818c9d21c078e8acd2f7b
   > Blocks: 0            Seconds: 0
   > contract address:    0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3
   > block number:        1
   > block timestamp:     1634730056
   > account:             0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac
   > balance:             1207825.819455434174706176
   > gas used:            159195 (0x26ddb)
   > gas price:           1 gwei
   > value sent:          0 ETH
   > total cost:          0.000159195 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:         0.000159195 ETH


2_deploy_contracts.js
=====================

   Deploying 'MyToken'
   -------------------
   > transaction hash:    0x0b42ece0d7c1cbbba5d55e77ffa2b520b6092e1ec2e9f0f09c9d461b7a4fc1e7
   > Blocks: 0            Seconds: 0
   > contract address:    0x3ed62137c5DB927cb137c26455969116BF0c23Cb
   > block number:        3
   > block timestamp:     1634730057
   > account:             0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac
   > balance:             1207825.818306403174706176
   > gas used:            1106693 (0x10e305)
   > gas price:           1 gwei
   > value sent:          0 ETH
   > total cost:          0.001106693 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:         0.001106693 ETH


Summary
=======
> Total deployments:   2
> Final cost:          0.001265888 ETH
  1. Open polkadot-js to view contract transactions

  2. You can see the balance by importing contract 0x3ed62137c5DB927cb137c264559116BF0c23Cb in metamask

  3. Transfer test (not supported?)
    Go to the address below
    Public Address: 0x3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0
    Private Key: 0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b

Posted by dodgei on Wed, 20 Oct 2021 09:25:59 -0700