เตรียมเครื่องมือสำหรับ Substrate Development

สำหรับบทความนี้จะเป็นบทความเกี่ยวกับการเตรียมเครื่องมือ การตั้งค่า สำหรับ Substrate Development กันนะครับ เนื่องจาก Substrate นั้น เขียนด้วยภาษา Rust สิ่งที่เราต้องทำก็คือติดตั้ง Rust และเตรียมความพร้อมเครื่องมือต่างๆ นั่นเอง
โดยจริงๆ แล้ว ก็จะคล้ายๆ ที่เขียนบทความไว้ใน บทความ ทดลองเขียน Smart Contract ด้วย ink! + Rust + Substrate
1. Install Rust
การติดตั้ง Rust จะใช้ Rustup ในการติดตั้ง (Windows จะได้ไฟล์ .exe
มา click install ได้เลย)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
เมื่อติดตั้งเรียบร้อยแล้ว สามารถเช็ค version ของ rustup ได้ แบบนี้
rustup --version
จะได้ผลลัพธ์ประมาณนี้ (ขึ้นอยู่กับ เวอร์ชั่นของแต่ละคน)
rustup 1.24.3 (ce5817a94 2021-05-31)info: This is the version for the rustup toolchain manager, not the rustc compiler.info: The currently active `rustc` version is `rustc 1.60.0 (7737e0b5c 2022-04-04)`
สิ่งที่ rustup ติดตั้งมา ก็จะมี
- rustc - เป็น Compiler สำหรับ Rust
- cargo - เป็นตัว Package Manager (เหมือน npm ของฝั่ง Node.js)
2. Rust toolchain
ในการพัฒนา Substrate เราต้องปรับ Rust toolchain เป็นเวอร์ชั่น latest stable และเป็นเวอร์ชั่น nightly ด้วย
rustup default stablerustup updaterustup update nightlyrustup target add wasm32-unknown-unknown --toolchain nightly
ทดสอบดูว่า Rust toolchain ตั้งค่าถูกมั้ย
rustup show
จะได้ผลลัพธ์เป็นแบบนี้ (ตัวอย่างของผมคือ Mac OS)
Default host: aarch64-apple-darwinrustup home: /Users/chai/.rustup
installed toolchains--------------------
stable-aarch64-apple-darwin (default)stable-x86_64-apple-darwinnightly-2022-03-14-aarch64-apple-darwinnightly-aarch64-apple-darwinbpf1.56.0-aarch64-apple-darwin
installed targets for active toolchain--------------------------------------
aarch64-apple-darwinwasm32-unknown-unknownwasm32-wasix86_64-apple-darwin
active toolchain----------------
stable-aarch64-apple-darwin (default)rustc 1.60.0 (7737e0b5c 2022-04-04)
ดูให้แน่ใจว่า installed targets for active toolchain มี wasm32-unknown-unknown
3. Substrate Contracts Node
ตัว Substrate Contracts Node เป็นเหมือนตัวที่ทำให้เราสามารถรัน Node Subtrate บนเครื่อง local ของเราได้ โดยใช้ node-template และ pallet-contracts
(ตัว Smart Contract Module)
วิธีการติดตั้ง ติดตั้งผ่าน Cargo (ตัวที่มาพร้อมกับ Rustup)
cargo install contracts-node --git https://github.com/paritytech/substrate-contracts-node.git --force --locked
จากนั้น เราสามารถ start server ได้ด้วยคำสั่ง
substrate-contracts-node --dev
4. Cargo Contract
ตัว Cargo Contract เป็น Command Line Interface สำหรับทำงานร่วมกับ Smart Contract และ ink!
ก่อนติดตั้ง ต้องติดตั้ง Dependencies ก่อน
brew install binaryen
สำหรับ Windows ดาวน์โหลดตัว version windows ที่นี่ binaryen release
ติดตั้ง cargo-dylint
cargo install cargo-dylint dylint-link
สุดท้าย ติดตั้ง cargo-contract
cargo install cargo-contract --force --locked
5. Polkadot.js & Client UI
Polkadot.js ส่วนนี้จะเป็นส่วน UI และ Frontend รวมถึง Wallet ครับ เป็น Optional แต่ถ้ามีก็ดีครับ
- https://polkadot.js.org/apps/# - เป็นเว็บ ที่ทำให้เราดู Block explorer เชื่อมต่อ Wallet ได้ทุกๆ chain/substrate ใน Polkadot ecosystem
- Polkadot Extension - ตัว Wallet Extension รองรับ Chrome / Firefox เป็นกระเป๋า Wallet คล้ายๆ Metamask แต่สำหรับ Polkadot
- Contract UI - เป็นเว็บให้เราสามารถ Deploy contract ได้ (ต้องเชื่อมกับ Substrate Contract Node ที่รัน local)
- Subscan - เป็นตัว Block Explorer แบบเดียวกับ Etherscan
References
- Authors
-
Chai Phonbopit
เป็น Web Dev ในบริษัทแห่งหนึ่ง ทำงานมา 10 ปีกว่าๆ ด้วยภาษาและเทคโนโลยี เช่น JavaScript, Node.js, React, Vue และปัจจุบันกำลังสนใจในเรื่องของ Blockchain และ Crypto กำลังหัดเรียนภาษา Rust