Appchain Development

# Appchain Development

In this tutorial, we will:

  1. Setup the development environment;
  2. Implement appchain runtime;
  3. Start the local testnet;

# Setup the Development Environment

It's suggested to start an Appchain node based on Barnacle (opens new window) which is a template developed by the Octopus Network team. Originating from the Substrate node template (opens new window), Barnacle is a minimal working Appchain node template for developers quickly start their Octopus Appchain project. The frontend of an Appchain can be developed based on the Front-end template (opens new window).

Note: Substrate development is easiest on Unix-based operating systems like macOS or Linux, and for Windows user, it is highly recommended to use Windows Subsystem Linux (WSL) and follow the instructions for Ubuntu/Debian.

For most users, you can execute the following commands to install the environment.

curl [https://getsubstrate.io](https://getsubstrate.io/) -sSf | bash -s - --fast

For more information, please refer to the Installation Guide (opens new window) in the Substrate Developer Center.

# Barnacle

Appchain node template Barnacle, it is based on the Substrate node template and integrates a series of octopus-pallets (opens new window) which were implemented by the Octopus network team, including:

git clone --depth 1 https://github.com/octopus-network/barnacle.git
cd barnacle
cargo build

Based on Barnacle, the appchain team only needs to focus on the pallets development of business function, and then they would integrated easily appchain into the Octopus network.

# Front-end template

# Install Node.js
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
nvm install node
# Install Yarn
npm install --global yarn
# Clone the frontend template from github
git clone -b v3.0.0+monthly-2021-08 --depth 1 https://github.com/substrate-developer-hub/substrate-front-end-template
# Install the dependencies
cd substrate-front-end-template
yarn install

Note

If there is a newer version of substrate-front-end-template, It is recommended to replace v3.0.0+monthly-2021-08 with it in the above command.

# Implement appchain runtime

Steps to implement an application specific pallets:

  1. Add a pallet, and implement application specific logic in pallets/<pallet-name>/src/lib.rs;
  2. Add the pallet into runtime/Cargo.toml, runtime/src/lib.rs;
  3. Add the runtime into node/Cargo.toml, install it in the node.

For more information, please refer to the Add Pallet to Runtime Guide (opens new window) in the Substrate Developer Center.

# Appchain configuration

The configuration of the appchain is mainly in the ChainSpec file. Need to configure:

  • Appchain pallet
    • Anchor contract;
    • Validator collection;
    • The number of tokens pre-mined on the NEAR network;

The Barnacle example is as follows:

"octopusAppchain": {
  "anchorContract": "barnacle.registry.test_oct.testnet",
  "validators": [
    [
      "5G6xVxyaS8PZargUL27pSEbhLQbRQJ2PBvrvXVpyjHzivQxs",
      10000000000000000000000
    ],
    [
      "5Dqg8gjTeM4it3mCaX1bdQmTT3GXgv7oSuZAfFUwJaTKuJfz",
      10000000000000000000000
    ],
    [
      "5Gj5yzSKtqkMM3j7FhRSWuybkwwms9KBPsAhyeobgmLD4r1g",
      10000000000000000000000
    ],
    [
      "5F42cCzboJhzfuVazARY6gFVpjwWMwAg1aG3pWF2aS76uu4Q",
      10000000000000000000000
    ]
  ],
  "preminedAmount": 500000000000000000000000000,
  "assetIdByName": [
    [
      "usdc.testnet",
      0
    ]
  ]
},
  • LPoS pallet
    • The historical cycle of LPoS rewards;
    • Rewards for each Era;

The Barnacle example is as follows:

"octopusLpos": {
  "historyDepth": 84,
  "eraPayout": 20000000000000000000000
},

# Start the Local Testnet

Execute the following command to compile and start the local blockchain node:

cargo build
# Run a temporary node in development mode
./target/debug/appchain-barnacle --dev --tmp

If you want to run a local front-end to interact with local nodes, you can refer to Run Local Front End (opens new window).

# Publish the Appchain Release

Once finishing the Appchain development, and the integration of the Octopus Pallets, the Appchain team needs to publish a release of the Appchain.

Note

Last Updated: 12/27/2021, 8:35:09 AM