在windows裡嘗試Solana

在windows裡嘗試Solana


Solana: HelloWorld (in win10)


首先,我們先安裝WSL Install WSL | Microsoft Docs

在WSL中安裝rust-lang相關套件 Using WSL, in wsl terminal:

sudo apt-get update
sudo apt install build-essential
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env #Import the environment config for rust
rustc --version #Test it

接著我們在WSL中安裝solana tool:

我們使用prebuilt binaries去安裝: 1.Download the file solana-release-x86_64-unknown-linux-msvc.tar.bz2

  1. in wsl terminal, run:
tar jxf solana-release-x86_64-unknown-linux-gnu.tar.bz2
cd solana-release/
export PATH=$PWD/bin:$PATH

Goto example-helloworld, and run :

cargo build-bpf --manifest-path=./src/program-rust/Cargo.toml --bpf-out-dir=dist/program

我們可以看到,正在build智能合約

接著我們能看到編譯完成後,出現了這些檔


我們將他deploy到我們的local網上

首先先產生key

solana-keygen new -o /home/chenfu0217/.config/solana/id.json

接著,我們將合約deploy到local網上

solana program deploy /mnt/f/\_workspace/BlockChain/solana/example-helloworld/dist/program/helloworld.so

We see

solana config set --url localhost

Set

Open new wsl terminal and run

solana-test-validator

Get problem(Solved)

這是因為WSL中目錄關係所造成的問題,使用”cd ~/“切換目錄 =>

Now we deploy it

open new terminal and run

export PATH=$PWD/bin:$PATH

And

solana program deploy /mnt/f/_workspace/BlockChain/solana/example-helloworld/dist/program/helloworld.so

Back to the origin terminal, and use npm to run

npm run start

we see

If we stop WSL And back to test, we see

Reference:

solana_program solana_sdk