Coder Social home page Coder Social logo

play's Introduction

play

My custom blockchain

Table of contents

Note: Generate a new chapter with openssl rand -hex 3

Quick start basic usage

Create blockchain from template

Create blockchain from template

Create a Substrate SRML-based blockchain.

  • Install Rust. Obtain and setup blockchain template
curl https://getsubstrate.io -sSf | bash
git clone https://github.com/shawntabrizi/substrate-package
cd substrate-package
git submodule update --init
./substrate-package-rename.sh my-node "My Org"
mv my-node ../ &&
mv substrate-module-template/ ../

Build blockchain

  • Install required tools and dependencies
  • Build the WebAssembly binary from all code
cd .. && \
cd my-node && \
./scripts/init.sh && \
./scripts/build.sh && \
cargo build --release

Save changes with Git

git add . && \
git commit -m "Initial node template" && \

Run blockchain node (full node)

  • Connect to development testnet (--chain development)
./target/release/my-node --dev

References

Update and maintain blockchain with latest dependencies

  • Run with detailed logs
RUST_LOG=debug RUST_BACKTRACE=1 ./target/release/my-node --dev
  • Add new runtime module
cd my-node && \
substrate-module-new <module-name> <author>
  • Update Rust dependencies
./scripts/init.sh
  • Re-build runtime (after changes). Purge chain of all blocks.
./target/release/my-node purge-chain --dev

./scripts/build.sh
cargo build --release

Create custom blockchain configuration

Production

  • Create latest chain specification code changes of local chain
mkdir -p ./src/chain-spec-templates
./target/release/my-node build-spec \
  --chain=local > ./src/chain-spec-templates/chainspec_latest.json
  • Create template chain specification from default local chain
mkdir -p ./src/chain-spec-templates
./target/release/my-node build-spec \
  --chain=local > ./src/chain-spec-templates/chainspec_default.json
mkdir -p ./src/chain-definition-custom
./target/release/my-node build-spec \
  --chain ./src/chain-spec-templates/chainspec_my.json \
  --raw > ./src/chain-definition-custom/mychain.json
  • TODO - Add Session and Staking SRMLs

Run multiple node PoA testnet using custom blockchain configuration

Development

./target/release/my-node \
  --base-path /tmp/polkadot-chains/alice \
  --dev \
  --name "My Testnet" \
  --telemetry-url ws://telemetry.polkadot.io:1024

Production

  • Run custom Substrate-based blockchain on local machine testnet with multiple terminals:
    • Imported custom chain definition for custom testnet
    • Use default accounts Alice and Bob as the two initial authorities of the genesis configuration that have been endowed with testnet units that will run validator nodes
    • Multiple authority nodes using the Aura consensus to produce blocks

Terminal 1: Alice's Substrate-based node on default TCP port 30333 with her chain database stored locally at /tmp/polkadot-chains/alice and where the bootnode ID of her node is Local node identity is: QmZ5kgdoLCx3Qfy8nJAiP1U9i6iY3qeiDNSCdHmHRJtSnF (peer id), which is generated from the --node-key value specified below and shown when the node is running. Note that --alice provides Alice's session key that is shown when you run subkey -e inspect //Alice, alternatively you could provide the private key to that is necessary to produce blocks with --key "bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice". In production the session keys are provided to the node using RPC calls author_insertKey and author_rotateKeys. If you explicitly specify a --node-key when you start your validator node, the logs will still display your peer id with Local node identity is: Qxxxxxx, and you could then include it in the chainspec.json file under "bootNodes". Also the peer id is listed when you go to view the list of full nodes and authority nodes at Polkadot.js Apps https://polkadot.js.org/apps/#/explorer/node:

./target/release/my-node --validator \
  --base-path /tmp/polkadot-chains/alice \
  --keystore-path "/tmp/polkadot-chains/alice/keys" \
  --chain ./src/chain-definition-custom/mychain.json \
  --key "bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice" \
  --node-key 88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee \
  --port 30333 \
  --telemetry-url ws://telemetry.polkadot.io:1024

Terminal 2: Bob's Substrate-based node on a different TCP port of 30334, and with his chain database stored locally at /tmp/polkadot-chains/alice. We'll specify a value for the --bootnodes option that will connect his node to Alice's bootnode ID on TCP port 30333:

./target/release/my-node --validator \
  --base-path /tmp/polkadot-chains/bob \
  --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/QmZ5kgdoLCx3Qfy8nJAiP1U9i6iY3qeiDNSCdHmHRJtSnF \
  --chain ./src/chain-definition-custom/mychain.json \
  --bob \
  --port 30334 \
  --telemetry-url ws://telemetry.polkadot.io:1024
  • Distribute the custom chain specification to allow others to synchronise and validate if they are an authority

  • Add session keys for other account(s) to be configured as authorities (validators)

    • TODO
  • View on Polkascan or Polkadot Telemetry

    • TODO - Register on Polkascan

Creating a new custom runtime modules

Import a template SRML module

Interact with blockchain using UI

{
  "Kitty": {
    "id": "Hash",
    "dna": "Hash",
    "price": "Balance",
    "gen": "u64"
  }
}

Create custom blockchain UI

Interact with blockchain using CLI

Other resources

play's People

Contributors

ltfschoen avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.