Cabal setup
Let us organise our code for this course project. We will be writing a number of Plutus validators and our project can have the same structure as plutus-scripts.
The .cabal file
We start off by creating a new directory and initialising a cabal project.
mkdir hpm-validators && cd hpm-validators
cabal initThis will create a default cabal project structure for us that looks like this:
├── app
│ └── Main.hs
├── CHANGELOG.md
└── hpm-validators.cabalWe will place all our source code in the src/ directory so let's rename the app directory to src. Inspecting the hpm-validators.cabal file shows that the project was initialised as an executable, but we will be building a library of validators so we can change that to a library and specify the hs-source-dirs to src. The rest of the file we can simply copy from the plutus-scripts.cabal template (most notably the build-depends section). Our complete hpm-validators.cabal file looks like this:
cabal-version: 2.4
name: hpm-validators
version: 0.1.0.0
-- A short (one-line) description of the package.
-- synopsis:
-- A longer description of the package.
-- description:
-- A URL where users can report bugs.
-- bug-reports:
-- The license under which the package is released.
-- license:
-- The package author(s).
-- author:
-- An email address to which users can send suggestions, bug reports, and patches.
-- maintainer:
-- A copyright notice.
-- copyright:
-- category:
extra-source-files: CHANGELOG.md
library
hs-source-dirs: src
exposed-modules: SimplestSuccess
build-depends: aeson
, base ^>=4.14.1.0
, bytestring
, containers
, cardano-api
, data-default
, freer-extras
, plutus-contract
, plutus-ledger
, plutus-ledger-api
, plutus-ledger-constraints
, plutus-script-utils
, plutus-tx-plugin
, plutus-tx
, text
, serialise
default-language: Haskell2010
ghc-options: -Wall -fobject-code -fno-ignore-interface-pragmas -fno-omit-interface-pragmas -fno-strictness -fno-spec-constr -fno-specialise
Our exposed-modules: exposes SimplestSuccess as that will be the first validator script we write.
The cabal.project file
We do not need to think too much about the cabal.project file. Simply copy the full file from plutus-scripts/cabal.project as it contains all the dependencies we need. For reference, the full file looks like this:
The project structure that we will create in this course looks like this:
Last updated