How to run the first smart contract on Local Plutus Playground (for MacOs | Linux)

KChain Solutions
3 min readJun 7, 2021

--

Plutus Playgroud

Plutus Playground is a tool that simulates the behavior of a Cardano blockchain to test the behavior of smart contracts.
This tutorial allows you to configure the playground on your computer until a dockerized version is available.

After I followed my first Cardano lecture, I want to share with you which are the steps to set up Plutus Playground on your local computer. You can run this procedure on Linux, Mac, or Windows WSL.

The advantages of local installation of Plutus playground are that you can choose the most up-to-date version compatible with your code

1. Install Nix

First of all, you have to install Nix. Nix is a package management and system configuration tool. It makes it possible to build reproducible, declarative, and reliable systems.

Terminal command to install Nix on Linux

sh <(curl -L https://nixos.org/nix/install)

How to install nix-shell on MacOs (I tried on BigSur Os):

sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume

2. Configure Nix

Create the file /etc/nix/nix.conf

with this content:

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=

3. Clone the repositories

git clone https://github.com/input-output-hk/plutus.git
git clone https://github.com/input-output-hk/plutus-pioneer-program
  • From the first line, you download the Plutus code. This code contains the Playground environment.
  • From the second you get the tutorial codes from the Pioneer program.
Repositories content

4. Check the Plutus Playground version

To be sure the version of the tutorial code will be compatible with the Plutus playground, you should check the tag from the cabal.project file.

vim ./plutus-pioner-program/code/week01/cabal.project

Then copy the tag and make the checkout to get the correct Plutus branch.

cd ./plutus
git checkout 3746610e53654a1167aeb4c6294c6096d16b0502

5. Launch nix-shell

If you are in the Plutus main folder you can launch nix-shell from the terminal. The first-time nix-shell could require a large amount of time (10–20 min).

nix-shell

Once you execute nix-shell it’s possible to start the Plutus server and the Plutus client.

5. Launch Plutus server

cd ./plutus-playground-serverplutus-playground-server

6. Launch Plutus client

Open the folder Plutus-playground-client with another terminal tab and execute the command:

npm run start

When the web-server is started you can open this URL (https://localhost:8009/) on your browser.

Plutus Playground is now ready to simulate your smart contracts.

--

--

KChain Solutions
KChain Solutions

Written by KChain Solutions

With expertise and dedication, we drive meaningful industry change, embracing the future of technology

No responses yet