https://learn.microsoft.com/ko-kr/windows/wsl/install
Anchor
솔라나는 Rust 라는 언어로 컨트랙트를 작성해 배포한다. 하지만, 쌩 Rust 로는 너무너무나 어렵고 관리가 힘들기에 Anchor 라는 Rust 프레임 워크를 사용한다. 하지만, Windows 상에서 anchor 설치 및 관리가 꽤 복잡하기에 이렇게 문서로 작성한다.
위의 링크에 따라서 WSL 환경에서 구현하려고 한다.
WSL 이란?
간단하게 말해서 윈도우 위에서 돌아가는 작은 컴퓨터다. VM 이 있지 않나요? 하신다면, VM 은 진짜 OS 를 새로 띄워 구동부터 하는 반면, WSL 은 윈도우 운영체제 안에 작은 디스크 조각안에서 가상머신 운영체제 명령어를 이용할 수 있는 기능이다. 윈도우와 파일교환이 가능하다.
1. WSL 설치
Powershell 혹은 cmd 창을 열어 wsl 을 설치한다.
wsl --install
2.
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
3.
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
4. 재부팅
5.
Rust & Cargo 설치
Rust를 설치하고 Cargo를 설치한다.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
- rustup 을 설치해 rust를 설치하고, cargo 를 설치한다.
6.
Node.js, NPM 설치
Anchor CLI와 프로젝트 초기화를 위해 Node.js를 설치해야 한다.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
nvm install 22
7. 솔라나 설치
sh -c "$(curl -sSfL https://release.solana.com/v1.16.5/install)"
8. Anchor 설치
npm i -g @coral-xyz/anchor-cli
9. 솔라나 cli 설치
solana config set --url localhost
solana config set --url https://api.devnet.solana.com
Config File: /home/lkbrothers/.config/solana/cli/config.yml
RPC URL: http://localhost:8899
WebSocket URL: ws://localhost:8900/ (computed)
Keypair Path: /home/lkbrothers/.config/solana/id.json
Commitment: confirmed
솔라나 키체인 생성
solana-keygen new
----
Generating a new keypair
For added security, enter a BIP39 passphrase
NOTE! This passphrase improves security of the recovery seed phrase NOT the
keypair file itself, which is stored as insecure plain text
BIP39 Passphrase (empty for none):
Wrote new keypair to /home/lkbrothers/.config/solana/id.json
=========================================================================
pubkey: "YOUR KEYCHAIN"
=========================================================================
Save this seed phrase and your BIP39 passphrase to recover your new keypair:
normal warm mercy fix leader crater cinnamon palm truly nice movie embark
=========================================================================
주소확인
solana address
앵커 인잇
Anchor 프로젝트가 생성된다.
anchor init my-project
4. 빌드 및 배포
로컬 밸리데이터 실행
로컬에서 실행되는 블록체인 환경이다. 실행하면 블록체인 시스템이 로컬에서 실행된다.
solana-test-validator
빌드
anchor build
배포
anchor deploy
에러 처리
- 솔라나 테스트 밸리데이터 오류
솔라나 테스트 밸리데이터 실행시 오류가 나왔다. 처음 ubuntu 실행환경에서는 bzip2 가 깔려있지 않아 깔아줘야한다.
sudo apt update
sudo apt install bzip2
2. 앵커 버전4 빌드 오류
There is an issue on the anchor repository for this: https://github.com/coral-xyz/anchor/issues/3392#issuecomment-2508412018
Fresh project `anchor build` fails with "lock file version 4 requires `-Znext-lockfile-bump`" · Issue #3392 · coral-xyz/anchor
Issue Running anchor build or anchor test in a fresh project initialized with anchor-cli fails with the following: error: failed to parse lock file at: /Users/{user}/{project_dir}/anchor/Cargo.lock...
github.com
The suggested solution is to change the lock file version from 4 to 3.
This is acherons answer to the issue which will be solved in Anchor version 2.x
You can fix this simply by changing the version field of Cargo.lock as #3393 (comment) suggested:
- version = 4
+ version = 3
The reason why it happens is because Anchor v0.30 uses Solana v1.18, and Solana v1.18 depends on rustc 1.75, but the new version (4) of Cargo.lock has only been stabilized in rustc 1.78 (as mentioned in rust-lang/cargo#14655 (comment)).
Solana build tools have recently been updated to use rustc 1.79, which is available since Solana v2.1, and it's also what the master branch of Anchor uses (#3339).
Anchor v0.31 (#3259) will support Solana v2, meaning this issue will be resolved automatically. In the meantime, you can just use the fix mentioned at the beginning of this comment.
If you are still having issues afterwards follow the guide from beeman here: https://github.com/coral-xyz/anchor/issues/3392#issuecomment-2565734744
Fresh project `anchor build` fails with "lock file version 4 requires `-Znext-lockfile-bump`" · Issue #3392 · coral-xyz/anchor
Issue Running anchor build or anchor test in a fresh project initialized with anchor-cli fails with the following: error: failed to parse lock file at: /Users/{user}/{project_dir}/anchor/Cargo.lock...
github.com
⇒ Cargo 최신버전이 4 인데 어째서인지 오류가 난다. 깃헙 이슈에도 해당 이슈가 나와있고, 문제가 있어 3으로 내리라고한다. lock 파일 버전을 변경해주자.
3. 빌드오류2
=> 링커 못찾음
링커를 찾지못하면 gcc, cc 등 c 기반 프로그램이 깔려있지 않아서다. 아래 방법대로 깔아주자.
1. 필수 패키지 설치 (Ubuntu/WSL 기준)
- 시스템 패키지 업데이트
sudo apt update sudo apt upgrade
- C 컴파일러 및 빌드 도구 설치
아래 명령어로 필요한 패키지를 설치합니다: sudo apt install build-essential
- 설치 확인
설치된gcc
및cc
의 버전을 확인합니다: gcc --version cc --version
2. Rust 및 Cargo 빌드 도구 재설치
Rust 및 Cargo 관련 문제가 있을 경우 재설치해보세요:
- Rust 재설치:
rustup self uninstall curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- 설치 후 Rust 버전 확인:
rustc --version cargo --version
3. 프로젝트 다시 빌드
필요한 도구를 설치한 후, Rust 프로젝트를 다시 빌드하세요:
cargo clean
cargo build