Substrate 개발 세팅

Yechan Jeon·2022년 1월 24일
0

Substrate

목록 보기
1/3
post-thumbnail

Development setting


이하의 과정은 유저의 os가 ubuntu 혹은 debian WSL2임을 가정합니다.

Required package

sudo apt update && sudo apt install -y git clang curl libssl-dev llvm libudev-dev

Rust and Rust toolchain 설치하기

  1. rustup
    curl https://sh.rustup.rs -sSf | sh

  2. PATH env에 cargo bin directory 추가
    source ~/.cargo/env

  3. configure rust toolchain

rustup default stable
rustup update
  1. nightly release , nightly WASM 추가
rustup update nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
  1. 설치 확인
rustc --version
rustup show

Substrate node template 준비하기

  1. clone node template repo
    git clone https://github.com/substrate-developer-hub/substrate-node-template

  2. template directory로 이동

cd substrate-node-template
#latest branch 사용
git checkout latest
  1. node template compile 하기
    cargo는 rust언어의 package manager이다.
    공식문서에서는 꼭 release flag를 붙여 compile 할 것을 요구함!!.
cargo build --release

Front-end template 설치하기

Substrate based blockchain node와 상호작용을 위해서 React로 렌더링을 진행한다.

  1. node.js와 yarn version확인
    front-end template을 사용하기에 앞서
    node --version, yarn --version으로 WSL2에 설치 되어있는지 확인한다.
    설치가 되어있지 않다면 공식페이지에서 설치 단계를 따르면 된다.
  1. front-end template git clone 하기
    git clone https://github.com/substrate-developer-hub/substrate-front-end-template
    이후 과정은 마찬가지로 해당 directory이동한 다음 latest branch로 checkout해주고 yarn을 통해 dependencies를 설치해주면 된다.
cd substrate-front-end-template
# We want to use the `latest` tag throughout all of this tutorial
git checkout latest
yarn install

현재 node.js LTS 17.+ version에서는 yarn install이 작동하지 않는 이슈가 있는데 해결되지는 않은 것 같다. lts/gallium version을 이용하면 원활한 진행이 가능하다.

Local substrate node 시작하기

  1. 다시 substrate-node-template으로 이동해준다.
  2. ./target/release/node-template --dev로 dev mode 실행
2022-01-24 11:43:48 🎁 Prepared block for proposing at 34 (0 ms) [hash: 0x7d443dbf0875680dc7c2ed0f33e8b7ebb923a4677cef12b28d31d85a6b7c9bb1; parent_hash: 0x4d1e…e18e; extrinsics (1): [0xa06e…8802]]
2022-01-24 11:43:48 🔖 Pre-sealed block for proposal at 34. Hash now 0xc5fd6264b7ebd7f02bf05f48accaf0286ebf9db339182bbbda8c982e84b40e7a, previously 0x7d443dbf0875680dc7c2ed0f33e8b7ebb923a4677cef12b28d31d85a6b7c9bb1.
2022-01-24 11:43:48 ✨ Imported #34 (0xc5fd…0e7a)
2022-01-24 11:43:51 💤 Idle (0 peers), best: #34 (0xc5fd…0e7a), finalized #32 (0x5730…31d3), ⬇ 0 ⬆ 0

진행이 성공적이라면 이와 유사한 결과를 볼 수 있다.
참고로 finalized뒤에 숫자가 계속해서 증가하는 것은 블록체인이 새로운 블록을 형성하고 consensus에 도달하는 중이라는 것을 의미함.

Browser에서 동작 확인하기

  1. node-template이 터미널에서 문제 없이 동작하는 것을 확인하고 새로운 터미널을 실행한다.(기존 터미널 종료하면 안됌)

  2. 새로운 터미널 창에서 substrate-frontend-template으로 이동하여
    yarn start실행.
    이것도 마찬가지로 latest lts는 안되는 듯..

  3. http://localhost:8000로 이동해서 확인하기.
    접속을 진행하기 위해 polkadot.js같은 extension이 필요함

profile
방황했습니다. 다시 웹 개발 하려고요!

0개의 댓글