Cardano 目前還沒有上線,測試網也還沒開放(2021年6月)。目前可以用來測試及練習的工具主要是 Plutus Playground。雖然沒有 Playground 也可以運行測試,但 Playground 還是很方便的。
Cardano 官方 IOHK 提供線上版本,也可以試用看看,但速度很慢,而且據說版本較舊,還是建議下載並安裝本地版本。線上版網址是:
https://playground.plutus.iohkdev.io/
我們開始安裝。這裡的步驟主要參考
https://www.reddit.com/r/cardano/comments/mmzut6/macos_plutus_playground_build_instructions/
我在我的 MacBook Pro 2019 macOS Big Sur 11.5 beta 上安裝成功。
1 — 安裝Nix
[$] sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume
2 — 關閉並重啓 Terminal (確保所有環境變數配置成功)
3 — 檢查 Nix 版本 (可做可不做)
[$] nix --version
4 — 建立 /etc/nix/nix.conf
[$] nano /etc/nix/nix.conf
5 — 將這兩行加入 nix.conf 檔案裡:
substituters = https://hydra.iohk.io https://iohk.cachix.org https://cache.nixos.org/trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= iohk.cachix.org-1:DpRUyj7h7V830dp/i6Nti+NEO2/nhblbov/8MW7Rqoo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
注意: 這兩行是要避免生成時間太久(其實這兩行是強迫使用 IOHK 版本而不是最新版。沒有這兩行會失敗,浪費我很多時間)
注意: 要檢查 /etc/nix 和 /etc/nix/nix.conf 是否已存在。如果沒有要用
[$] mkdir /etc/nix
[$] touch /etc/nix/nix.conf
6 — 重新啟動電腦
7 — 使用 git 下載 plutus
[$] git clone https://github.com/input-output-hk/plutus.git
8 — 以下的命令要在 plutus 目錄下執行
[$] cd plutus
9 — 生成Plutus Core 這個步驟很花時間,可能要幾個小時
[$] nix build -f default.nix plutus.haskell.packages.plutus-core.components.library
注意:
有些MacOS BigSur 的用戶回報以下的錯誤:
error: while setting up the build environment: getting attributes of path '/usr/lib/libSystem.B.dylib': No such file or directory
要解決這問題必須將 nix 改為 unstable 版本的 nixpkgs
[$] sudo nix-channel --add https://nixos.org/channels/nixpkgs-unstable unstable
注意:
如果出現以下錯誤:
"error: refusing to create Nix store volume ... boot volume is FileVault encrypted"
必須要參考以下這兩篇:
https://github.com/digitallyinduced/ihp/issues/93#issuecomment-766332648
https://www.philipp.haussleiter.de/2020/04/fixing-nix-setup-on-macos-catalina/
10 — 生成Plutus Playground Client / Server
[$] nix-build -A plutus-playground.client[$] nix-build -A plutus-playground.server
11 — 生成Plutus Playground 其他部份
[$] nix-build -A plutus-playground.generate-purescript[$] nix-build -A plutus-playground.start-backend[$] nix-build -A plutus-pab
12 — 啟動nix-shell,這個步驟也可能花很多時間
[$] nix-shell
13 — 進入到 nix-shell 之後
[nix-shell] cd plutus-pab[nix-shell] plutus-pab-generate-purs[nix-shell] cd ../plutus-playground-server[nix-shell] plutus-playground-generate-purs
14 — 啟動playground server
[nix-shell] plutus-playground-server
15 — 開啟新的terminal:
[nix-shell] cd plutus[nix-shell] nix-shell[nix-shell] cd plutus-playground-client
16 — 啟動 playground client
[nix-shell] npm run start
這樣就成功了!
打開瀏覽器,如果有安全警告忽略:
如果 localhost 無法使用,試試
