You are on page 1of 6

Install Window Subsystem for Linux:

Cách 1:

Tham khảo: https://docs.microsoft.com/en-us/windows/wsl/install-manual#downloading-distros

Click to download Ubuntu 20.04 (hoặc bản linux quen thuộc với bạn):

Vào thư mục Download, click “” để cài đặt, sau đó window search và open Ubuntu 20.04 LTS
Cách 2:

Open Microsoft Store -> search “Ubuntu 20.04 LTS” -> Install -> Launch.

Install Node.js và npm:

Tham khảo:

https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04

https://github.com/nodesource/distributions#debmanual

1. Open Ubuntu 20.04 LTS


2. $ sudo apt update
3. $ curl -fsSL https://deb.nodesource.com/setup_12.x | sudo -E bash –
Nếu bạn gặp issue như bên dưới:
W: GPG error: https://deb.nodesource.com/node_12.x focal InRelease: The following signatures
couldn't be verified because the public key is not available: NO_PUBKEY 1655A0AB68576280
Sử dụng command bên dưới để fix:
$ KEYRING=/usr/share/keyrings/nodesource.gpg
$ curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee
"$KEYRING" >/dev/null
$ gpg --no-default-keyring --keyring "$KEYRING" --list-keys
4. $ sudo apt-get install -y nodejs
5. $ node –-version // v12.22.5
6. $ sudo apt install npm
7. $ npm –-version // 6.14.4
8. # To install the Yarn package manager, run:
9. $ curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee
/usr/share/keyrings/yarnkey.gpg >/dev/null
10. $ echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable
main" | sudo tee /etc/apt/sources.list.d/yarn.list
11. $ sudo apt-get update && sudo apt-get install yarn
Install the latest Rust: stable from  Install Rust - Rust Programming Language (rust-lang.org)

1. Open Ubuntu 20.04 LTS


2. $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
3. $ rustup –V // check version rustup
4. $ cargo –V // check version cargo
5. $ rustc –V // check version rustc

Alias with Ubuntu:

Alias là một dạng set up các shortcut command để dễ dàng sử dụng trong linux:

Ưu điểm:

- không cần phải nhớ 1 câu lệnh khá dài ngoằn mà chỉ cần nhớ keyWords để run dòng lệnh.
- Tiện dụng: rất tiện trong việc set up environment để code.
- …

Cách dùng:

1. Tạo file ~/.alias_profile


2. $ Code ~/.alias_profile
3. Set up dòng lệnh:
4. Systax: alias <Name of shortcut>='< the command 1 ; the command 2 (if any)>'

Example:

5. Sử dụng shortcut command:


6. $ source ~/.alias_profile // Load all alias shortcut command in file to the terminal
7. $ SolAirdrop 5 my_solana_wallet.json // $1: amount $2: address wallet // get 5 sol airdrop
Run Visual Studio Code in Ubuntu 20.04 LTS:

Tham khảo: https://code.visualstudio.com/docs/remote/wsl

1. # Install Visual Studio Code on the Windows side (not in WSL)


2. # Install the Remote Development extension pack.
3. # Open Ubuntu 20.04 LTS
4. $ mkdir
5. $ cd WorkingPlace
6. $ git clone https://github.com/solana-labs/example-helloworld.git
7. $ cd example-helloworld
8. $ Code .
Build solana program hello world:

Tham khảo: example-helloworld/README.md at master · solana-labs/example-helloworld · GitHub

1. # Open new Ubuntu 20.04 LTS


2. # Start a local Solana cluster:
3. $ solana-test-validator

1. # Open new Ubuntu 20.04 LTS


2. $ solana logs

1. # Open new Ubuntu 20.04 LTS


2. $ cd WorkingPlace/ example-helloworld
3. # Tạo mới ví mới và lưu trong file ~/.config/solana/id.json
4. $ solana-keygen new --no-passphrase –force
5. # Show public key
6. $ solana-keygen pubkey ~/.config/solana/id.json
7. # Airdrop SOL to wallet
8. $ solana airdrop 10 ~/.config/solana/id.json
9. # Show balace wallet
10. $ solana balance ~/.config/solana/id.json
11. # Set CLI config url to localhost cluster
12. $ solana config set --url localhost

Install npm dependencies:


$ npm install
Note: I used to this command, but the program didn’t work. So, I suggest to use “yarn install”
13. # Install yarn dependencies
14. $ yarn install

15. # Build the on-chain program


16. $ npm run build:program-rust
17. # Deploy the on-chain program
18. $ solana program deploy dist/program/helloworld.so
19. # Run the JavaScript client
20. $ npm run start

You might also like