Write Cardano smart contracts in Haskell
plinthc is GHC with the Plinth compiler built in. Plinth (formerly Plutus Tx) is a subset of Haskell compiled to Plutus Core, the language the Cardano ledger runs on-chain.
{-# LANGUAGE TemplateHaskell #-}
module MyValidator where
import PlutusTx
import PlutusTx.Prelude qualified as PlutusTx
-- The on-chain rule: ordinary Haskell, in the Plinth subset.
mustEqual :: Integer -> Bool
mustEqual redeemer = redeemer PlutusTx.== 42
-- The untyped wrapper the ledger runs.
untypedValidator :: BuiltinData -> PlutusTx.BuiltinUnit
untypedValidator arg =
PlutusTx.check (mustEqual (PlutusTx.unsafeFromBuiltinData arg))
-- Compiled to Plutus Core by plinthc, at compile time.
validatorCode :: CompiledCode (BuiltinData -> PlutusTx.BuiltinUnit)
validatorCode = $$(PlutusTx.compile [|| untypedValidator ||])
A complete validator. No plugin flags, no INLINEABLE
pragmas: build it with cabal build and plinthc emits the
Plutus Core. See
Test a Plinth contract locally
for the tests that go with it.
Why plinthc
GHC with Plinth built in
There is no plugin to install or configure. Point cabal at plinthc and it behaves like an ordinary GHC. When a module defines Plinth code, the compiler emits the Plutus Core next to the usual outputs.
Installs with ghcup, next to your GHC
One ghcup install gives you a binary for Linux (x86_64 and aarch64, glibc and musl), macOS (Apple Silicon) or Windows. plinthc never replaces your ghc. Releases track GHC 9.12 and GHC 9.6.
The whole Haskell ecosystem
Write the on-chain validator and the off-chain code in one language, even in one file. The same types cross the on-chain boundary safely. Use cabal, GHCi and Hackage as you do today.
No INLINEABLE pragmas, works at -O0
plinthc keeps the definitions the Plinth compiler needs available without pragmas, and its base, ghc-prim and ghc-bignum libraries ship ready for Plinth. You can build Plinth code with -O0.
Reproducible Plutus Core
The Plinth translation depends on how GHC compiles the code around it. plinthc pins the compiler and the Plinth compiler together and validates them as one unit, with tests and benchmarks.
Blueprints and local tests
Generate CIP-57 blueprints from Haskell values. Test a contract without a node: as plain Haskell, on the CEK machine, by its execution budget, or on a simulated ledger.
Documentation
This documentation follows the Diataxis framework, which separates docs into four kinds by what you need from them. New to Plinth? Start with Your first smart contract with Plinth.
Explanation
Understanding-oriented. Background and discussion: what Plinth is and how the compiler works.
Tutorials
Learning-oriented. Start here if you are new: hands-on lessons that walk you through compiling your first smart contract and running it on a local chain.
How-to guides
Task-oriented. Practical recipes for a specific job: install the compiler, use it in a project, test a contract, and generate a blueprint.
Reference
Information-oriented. Dry facts to look up.
About
plinthc is developed by ICAN Group (Luite Stegeman and Sylvain Henry). It is a fork of GHC, the Glasgow Haskell Compiler, with the Plinth compiler built in.
The Plinth compiler itself, the plutus-tx-plugin, is
developed by the Plutus team. See the
Plinth documentation
and the plutus repository.
The source code is on GitHub:
- ican-group/plinthc: the build scripts, the tests, the examples and the issue tracker.
- ican-group/ghc-plinth: the GHC fork.
- ican-group/ghc-plinth-plutus: the plutus fork, which supplies the Plinth compiler and libraries.