Running a local version of Plutus playground
Objective:
To run the playground server locally to test Plutus smart contracts.
Step 1: Install the nix package manager and the IOHK binary cache
To install it on most Linux distributions, download and run the installation script.
sh <(curl -L https://nixos.org/nix/install) --no-daemon
Follow the directions and then log out and back in.
Optional: enable IOHK's binary cache
When the binary cache is enabled, the build steps will tend to be faster.
sudo mkdir -p /etc/nix
cat <<EOF | sudo tee /etc/nix/nix.conf
substituters = https://hydra.iohk.io https://cache.nixos.org/
trusted-substituters =
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
EOF
Step 2: Clone the following 2 repositories to the local disk
Plutus pioneer course
git clone https://github.com/input-output-hk/plutus-pioneer-program
Plutus apps
git clone https://github.com/input-output-hk/plutus-apps
Step 3: Checkout the correct commit Plutus-apps repository
We want to make sure our playground server is running on the correct version. (The same version that our test contract was created on.)
cd ~/plutus-pioneer-program/code/week01
cat cabal.project
Find the entry marked https://github.com/input-output-hk/plutus-apps then copy the tag
Example entry: (Note tag 41149926c108c71831cfe8d244c83b0ee4bf5c8a is subject to change)
source-repository-package
type: git
location: https://github.com/input-output-hk/plutus-apps.git
tag: 41149926c108c71831cfe8d244c83b0ee4bf5c8a
subdir:
freer-extras
playground-common
plutus-chain-index-core
plutus-contract
plutus-ledger
plutus-ledger-constraints
quickcheck-dynamic
Step 4: Checkout the correct tag commit from the Plutus-apps repository
Verify you have checked out the correct commit:
cd ~/plutus-apps
~/plutus-apps$ git log
commit 41149926c108c71831cfe8d244c83b0ee4bf5c8a (HEAD)
If, not run the following command
git checkout 41149926c108c71831cfe8d244c83b0ee4bf5c8a
(Note commit tag is subject to change)
Step 5: Compile the Smart contract exercise
(a) In the Plutus-apps repo go to nix-shell:
~/plutus-apps$ nix-shell
(b) From the nix-shell command line go to the Plutus pioneer exercise folder:
cd ~/plutus-pioneer-program/code/week01
Example:
[nix-shell:~/plutus-apps]$ cd ~/plutus-pioneer-program/code/week01
[nix-shell:~/plutus-pioneer-program/code/week01]$
(c) Then update:
cabal build
Once compiled successfully we are ready to run it on the playground server.
[nix-shell:~/plutus-pioneer-program/code/week01]$ cabal build
Up to date
Step 5: Run the Plutus playground server
(a) From the nix-shell command line go to
cd ~/plutus-apps/plutus-playground-client
(b) Run Plutus playground server (it should show running on the port)
[nix-shell:~/plutus-apps/plutus-playground-client]$ plutus-playground-server
plutus-playground-server: for development use only
[Info] Running: (Nothing,Webserver {_port = 8080, _maxInterpretationTime = 80s})
Initializing Context
Initializing Context
Warning: GITHUB_CLIENT_ID not set
Warning: GITHUB_CLIENT_SECRET not set
Warning: JWT_SIGNATURE not set
Interpreter ready
[Debug] Failed to extract github token at step: "Reading cookies."
[Debug] Authentication status is: AuthStatus {_authStatusAuthRole = Anonymous}
(c) Open a new tab and still in the nix-shell go to :
cd ~/plutus-apps/plutus-playground-client
and do: npm run start
[nix-shell:~/plutus-apps/plutus-playground-client]$ npm run start
> plutus-playground-client@1.0.0 start /home/ntfreem/plutus-apps/plutus-playground-client
> plutus-playground-generate-purs && npm install && npm run install:spago && npm run build:webpack:dev
Step 5: Accessing local playground server
Once the above steps have been completed successfully you can access the playground interface in the web browser here:
https://localhost:8009/
Copy and paste the code to compile it