Plutus.V1.Ledger.Examples
1. 📜 Overview
2. 🔧 LANGUAGE PRAGMAS AND IMPORTS
3. ⚙️ Example Scripts
3.1 ✅ alwaysSucceedingNAryFunction
3.2 ❌ alwaysFailingNAryFunction
3.3 ➕ summingFunction
3.4 🧂 saltFunction
4. 📚 Glossary
1 📜 Overview
This Plutus.V1.Ledger.Examples module provides hand-crafted Plutus Core scripts for testing:
N‑ary scripts that always succeed or always fail, parameterized by the number of lambda arguments.
A simple addition script.
A salting wrapper to change a script’s hash without altering its behavior.
These functions produce SerializedScript values suitable for exercise or regression tests and should never be used in production code.
2 🔧 LANGUAGE PRAGMAS AND IMPORTS
TypeApplications: for literal constants in
summingFunction.StrictData: to avoid lazy fields in any data (though minimal here).
Imports for CBOR serialization, byte conversion, natural numbers, and Plutus Core.
3 ⚙️ Example Scripts
3.1 ✅ alwaysSucceedingNAryFunction
Inputs: arity
n :: Natural.Processing: constructs an
n‑argument lambda chain whose final body returns its first parameter, guaranteeing success.Output: serialized script that always succeeds when applied to
narguments.
Example:
3.2 ❌ alwaysFailingNAryFunction
Inputs: arity
n :: Natural.Processing: builds an
n‑argument lambda chain ending inError, so it always fails.Output: serialized script that throws an error regardless of arguments.
Example:
3.3 ➕ summingFunction
Inputs: none.
Processing: applies the
AddIntegerbuiltin to the constants 1 and 2.Output: serialized script computing
1 + 2.
Example:
3.4 🧂 saltFunction
Inputs:
salt :: Integerand existing scriptb0.Processing: deserializes
b0, wraps it with a new lambda accepting the salt, then applies it to the salt constant—preserving behavior but changing the hash.Output: new serialized script with different on-chain hash but identical core logic.
Example:
4 📚 Glossary
SerializedScript: a
ShortByteStringrepresenting a Plutus Core program.DeBruijn index: nameless variable representation by integer depth.
LamAbs: lambda abstraction in UPLC.
Error: runtime failure construct in UPLC.
Builtin: Plutus Core built‑in functions (e.g.,
AddInteger).Script hash: ledger‑computed hash of serialized script; used for on‑chain references.
Salt: additional argument to change script hash without modifying logic.
Last updated