Open ChristianoBraga opened 2 years ago
Instructions: Build Plutus Playground
/etc/nix/nix.conf
to include IOHK binary caches. (https://github.com/input-output-hk/plutus/blob/master/README.adoc#iohk-binary-cache)plutus-apps
: https://github.com/input-output-hk/plutus-apps.plutus-apps
repository and build the Plutus playground client/server:
nix-build -A plutus-playground.client
nix-build -A plutus-playground.server
nix-build -A plutus-playground.generate-purescript
nix-build -A plutus-playground.start-backend
nix-shell
, cd into the plutus-playground-client
folder and start the playground server as below.
[nix-shell:~/plutus-apps/plutus-playground-client]$ plutus-playground-server -i 120s
nix-shell
at the same folder, and start the playground client:
[nix-shell:~/plutus-apps/plutus-playground-client]$ npm run start
Runs like a charm! Except for the fact that I needed to invoke nix-shell
using nix-shell --extra-experimental-features flakes
.
From @ChristianoBraga:
So if you guys want to run the example I have shown today to generate the UPLC code,
plutus-apps/plutus-contract
.cabal update ; cabal build ; cabal repl
import PlutusTx
import Prettyprinter
:l test.hs
, where test.hs
is the code below-- Necessary language extensions for the Plutus Tx compiler to work.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ImportQualifiedPost #-}
module BasicPlutusTx where
import PlutusCore.Default qualified as PLC
-- Main Plutus Tx module.
import PlutusTx
-- Additional support for lifting.
import PlutusTx.Lift
-- Builtin functions.
import PlutusTx.Builtins
-- The Plutus Tx Prelude, discussed further below.
import PlutusTx.Prelude
-- Setup for doctest examples.
-- $setup
-- >>> import Tutorial.PlutusTx
-- >>> import PlutusTx
-- >>> import PlutusCore
-- >>> import PlutusCore.Evaluation.Machine.Ck
-- >>> import Data.Text.Prettyprint.Doc
integerOne :: CompiledCode Integer
{- 'compile' turns the 'TExpQ Integer' into a
'TExpQ (CompiledCode Integer)' and the splice
inserts it into the program. -}
integerOne = $$(compile
{- The quote has type 'TExpQ Integer'.
We always use unbounded integers in Plutus Core, so we have to pin
down this numeric literal to an ``Integer`` rather than an ``Int``. -}
[|| (1 :: Integer) ||])
pretty $ getPlc integerOne
Instructions: Build Plutus Playground
- git clone
plutus-apps
: https://github.com/input-output-hk/plutus-apps.
Most of the apps failed to build in my environment. I only managed to build plutus-contract
and plutus-playground-client
.
plutus-pioneer-program
cabal.project
of that week and look for the hash of plutus-apps
commit to be used. plutus-apps
and checkout that commit.nix-shell
on plutus-apps
dir.build-and-serve-docs
. This will allow to browse haddock doc locally (http://0.0.0.0:8002/haddock/). And possibly consistent with the version (commit) of plutus-apps
being used.pultus-pioneer-program
. cabal build
and cabal repl
on it.prettyprinter ^>=1.7.1
to section build-depends
to file plutus-pioneer-program-week05.cabal
.plutus-pioneer-program/code/week05/src/Week05/Free.hs
, and add the following lines after mkPolicy () _ = True
.
compiledPolicy :: PlutusTx.CompiledCode (BuiltinData -> BuiltinData -> ())
compiledPolicy = $$(PlutusTx.compile [|| Scripts.wrapMintingPolicy mkPolicy ||])
cabal repl
. It will start the Haskell interpeter.import Prettyprinter
b. import PlutusTx
c. pretty $ getPlc $ compiledPolicy
d. pretty $ simplifyProgram $ getPlc $ compiledPolicy
gets rid of (force _ (delay _))
.Take Week05 of Plutus Pioneer Program as basis, considering the previous comment adding compiledPolicy
to Free.hs
.
Add the following to plutus-pioneer-program-week05.cabal
. (Note: this not optimal. There may be some unnecessary imports.)
executable trivpol
main-is: main.hs
hs-source-dirs: src,.
exposed-modules: Week05.Free
, Week05.Homework1
, Week05.Homework2
, Week05.NFT
, Week05.Signed
, Week05.Solution1
, Week05.Solution2
build-depends: aeson
, base ^>=4.14.1.0
, containers
, data-default
, freer-extras
, playground-common
, plutus-contract
, plutus-ledger
, plutus-ledger-api
, plutus-ledger-constraints
, plutus-tx-plugin
, plutus-tx
, text
, prettyprinter ^>=1.7.1
, plutus-core ^>=0.1.0.0
, prettyprinter-configurable ^>=0.1.0.0
default-language: Haskell2010
Create the file main.hs
at .../plutus-pioneer-program/code/week05
with the following code:
import Week05.Free
import PlutusTx
import Prettyprinter
import PlutusPrelude
import UntypedPlutusCore
main :: IO()
main = do
putStrLn $ show $ pretty $ simplifyProgram $ getPlc $ compiledPolicy
The Plutus IR version of the policy is way smaller. The UPLC code has 1.2M whereas its PIR counter part has 204K.
import Week05.Free
import PlutusTx
import Prettyprinter
import PlutusPrelude
import UntypedPlutusCore
main :: IO()
main = do
writeFile "trivial-policy.uplc" $ show $ pretty $ simplifyProgram $ getPlc $ compiledPolicy
writeFile "trivial-policy.pir" $ show $ pretty $ getPir compiledPolicy
The command to generate the uplc
code should be this one:
writeFile "trivial-true-policy-print-classic-debug.uplc" $ show $ prettyPlcClassicDebug $ simplifyProgram $ getPlc $ compiledPolicyTrue
Sucessful install but
MyPlutusStarter
does not work./etc/nix/nix.conf
to include IOHK binary caches. (https://github.com/input-output-hk/plutus/blob/master/README.adoc#iohk-binary-cache)nix-shell
fromMyPlutusStarter
.cabal update
andcabal build
in the nix-shell.cabal build plutus-starter-pab
in the nix-shell.cabal exec -- plutus-starter-pab
in the nix-shell.curl -s http://localhost:9080/api/contract/definitions | jq
. You should see:Other things that do not work
Vscode and devcontainer
I am following the steps with vscode and docker for now. Don't forget to follow https://docs.docker.com/engine/install/linux-postinstall/. If you do not get your user to be added to docker group, follow https://stackoverflow.com/questions/56305613/cant-add-user-to-docker-group/66297855#66297855.b.Should you need to move your directory to another place, I recommend cleaning up and going through all steps once again.Cabal+Nix build with nix running in a docker image
docker run -it -v /data/IOG/MyPlutusStarter/:/MyPlutusStarter nixos/nix
where/data/IOG/MyPlutusStarter/
is the absolute path to your plutus-starter clone directory./MyPlutusStarter
is where it will be mounted in within your Docker image fs.nix-env -iA nixpkgs.emacs
or a similar command for your preferred editor./etc/nix/nix.conf
to include IOHK binary caches. (https://github.com/input-output-hk/plutus/blob/master/README.adoc#iohk-binary-cache)nix-shell
fromMyPlutusStarter
.cabal update
andcabal build
.curl
and other commands. My docker image was taking all my root space so I had to relocate it. After that, I have lost all my images. I will restart by installing everything locally.