@@ -4,24 +4,49 @@ permalink: /tutorials/first-smart-contract/
44---
55Before writing a real validator, it helps to get the whole toolchain working
66end to end with the simplest possible Plinth program: a function that adds two
7- numbers. In this tutorial you will create a tiny project from scratch, compile
8- it with ` uplc-ghc ` , run it, and read the Plutus Core it produced.
7+ numbers. In this tutorial you will install ` uplc-ghc ` , create a tiny project
8+ from scratch, compile it , run it, and read the Plutus Core it produced.
99
1010This tutorial targets ** Linux** . Windows and macOS walkthroughs will follow
1111later.
1212
1313## Before you start
1414
15- You need ` uplc-ghc ` installed. If you do not have it yet, follow
16- [ Install Plinth standalone compiler] ({% link how-to/install.md %}) first &mdash ;
17- this tutorial waits for you here. If you installed it via ghcup (the
18- recommended way), the binary is simply ` uplc-ghc ` on your ` PATH ` : wherever
19- this tutorial says ` /path/to/uplc-ghc ` , write plain ` uplc-ghc ` instead. If
20- you built from source, use the path of the binary the build produced.
15+ You need on ` PATH ` :
2116
22- You will also need a recent ` cabal ` (3.8 or newer) on your ` PATH ` .
17+ - [ ghcup] ( https://www.haskell.org/ghcup/ ) 0.2.1.0 or newer (check with
18+ ` ghcup --version ` );
19+ - a recent ` cabal ` (3.8 or newer);
20+ - ghcup's ` bin ` directory, ` ~/.ghcup/bin ` by default, where the compiler
21+ installed in step 1 lands. The standard ghcup setup adds it to ` PATH `
22+ already.
2323
24- ## Step 1: Create the project
24+ The rest of the tutorial assumes the compiler is available as plain
25+ ` uplc-ghc ` , which is what step 1 gives you. If you
26+ [ built it from source] ({% link how-to/build.md %}) instead, replace ` uplc-ghc `
27+ with the path of the binary the build produced.
28+
29+ ## Step 1: Install Plinth
30+
31+ ` uplc-ghc ` is distributed via ghcup as a custom tool named ` plinth ` (see
32+ [ Install Plinth standalone compiler] ({% link how-to/install.md %}) for the
33+ details). Add the Plinth release channel, then install and activate the tool:
34+
35+ ``` console
36+ $ ghcup config add-release-channel https://raw.githubusercontent.com/input-output-hk/ghc-plinth/ghcup-channel/ghcup-plinth.yaml
37+ $ ghcup install plinth latest
38+ $ ghcup set plinth latest
39+ ```
40+
41+ Check that the compiler is on ` PATH ` :
42+
43+ ``` console
44+ $ uplc-ghc --version
45+ ```
46+
47+ If you have already installed it this way, skip to step 2.
48+
49+ ## Step 2: Create the project
2550
2651Make a new directory and add the three files below.
2752
@@ -33,7 +58,7 @@ crypto C libraries (`libsodium`, `secp256k1`, `blst`) from source via the
3358` *-clib ` blocks, so you do not need them installed on your system:
3459
3560``` haskell
36- with- compiler: / path / to / uplc- ghc
61+ with- compiler: uplc- ghc
3762
3863packages: .
3964
@@ -183,7 +208,7 @@ The typed quote `[|| addTyped ||]` and the `compile` splice are the only
183208Plinth-specific pieces; ` PlutusTx.Prelude ` (imported as ` Tx ` ) supplies the
184209on-chain ` + ` , and everything else is ordinary Haskell.
185210
186- ## Step 2 : Build it
211+ ## Step 3 : Build it
187212
188213``` console
189214$ cabal update
@@ -195,7 +220,7 @@ from source, so expect it to take a while. Because the Plinth plugin is built
195220into ` uplc-ghc ` , no extra plugin configuration is required: the ` compile ` splice
196221is translated to Plutus Core as part of the normal build.
197222
198- ## Step 3 : Run it
223+ ## Step 4 : Run it
199224
200225``` console
201226$ cabal run plinth-add
@@ -204,7 +229,7 @@ $ cabal run plinth-add
204229` main ` runs and writes the compiled program to ` add.uplc ` in the current
205230directory.
206231
207- ## Step 4 : Look at the Plutus Core
232+ ## Step 5 : Look at the Plutus Core
208233
209234``` console
210235$ cat add.uplc
0 commit comments