Plutus.V1.Ledger.Scripts

  • 1. πŸ“œ Overview

  • 2. πŸ”§ LANGUAGE PRAGMAS AND IMPORTS

  • 3. πŸ—„οΈ Core Types

    • 3.1 πŸ–₯️ Script

    • 3.2 πŸ“ Validator, MintingPolicy, StakeValidator

    • 3.3 πŸ“Š Datum, Redeemer, Context

    • 3.4 πŸ”‘ Hash Types

    • 3.5 βš™οΈ ScriptError

  • 4. βš™οΈ Key Functions

    • 4.1 πŸ“ scriptSize

    • 4.2 πŸ”„ fromCompiledCode

    • 4.3 πŸ—οΈ applyArguments

    • 4.4 πŸš€ evaluateScript

    • 4.5 🎬 runScript / runMintingPolicyScript / runStakeValidatorScript

    • 4.6 πŸ”— applyValidator / applyMintingPolicyScript / applyStakeValidatorScript

    • 4.7 πŸ“š unitDatum, unitRedeemer

  • 5. 🀝 Typeclass Instances

  • 6. 🏭 On-Chain Derivations

  • 7. πŸ“š Glossary


1 πŸ“œ Overview

The Plutus.V1.Ledger.Scripts module provides the core abstractions and utilities for working with on-chain scripts in Plutus:

  • Script: opaque representation of a UPLC program.

  • Wrappers: Validator, MintingPolicy, and StakeValidator for specific script roles.

  • Data wrappers: Datum, Redeemer, and Context for script inputs.

  • Hash types: ScriptHash, ValidatorHash, DatumHash, etc., for script identification.

  • Evaluation: functions to apply and run scripts, extracting budgets and logs.

  • Utilities: scriptSize, fromCompiledCode, applyArguments, and example unitDatum/unitRedeemer.


2 πŸ”§ LANGUAGE PRAGMAS AND IMPORTS

  • Extensive pragmas for generics, template Haskell, and disabling warnings for orphans and name shadowing.

  • Imports for serialization, ByteString, builtins, and untpye UPLC modules.


3 πŸ—„οΈ Core Types

3.1 πŸ–₯️ Script

  • Opaque wrapper around UPLC Program.

  • Instances: Generic, NFData, Serialise via Flat.

3.2 πŸ“ Validator, MintingPolicy, StakeValidator

  • Role-specific wrappers adding Eq, Ord, Serialise, Pretty via LedgerBytes.

3.3 πŸ“Š Datum, Redeemer, Context

  • Wrap BuiltinData for script inputs and blockchain context.

3.4 πŸ”‘ Hash Types

  • String literals via IsString, Eq, Ord, ToData, FromData, UnsafeFromData, Pretty via LedgerBytes.

3.5 βš™οΈ ScriptError

  • Captures expected user errors vs internal evaluation exceptions.


4 βš™οΈ Key Functions

4.1 πŸ“ scriptSize

  • Returns serialized program size.

4.2 πŸ”„ fromCompiledCode

  • Converts GHC-compiled Plutus Tx code into nameless Script.

4.3 πŸ—οΈ applyArguments

  • Applies a list of Data arguments to a UPLC program.

4.4 πŸš€ evaluateScript

  • Runs the CEK evaluator, returning resource budget and log, or throws ScriptError.

4.5 🎬 runScript / runMintingPolicyScript / runStakeValidatorScript

  • Helper functions combining application and evaluation.

4.6 πŸ”— applyValidator / applyMintingPolicyScript / applyStakeValidatorScript

  • Applies wrapper types to produce a Script with applied arguments.

4.7 πŸ“š unitDatum, unitRedeemer

  • Convenience values for () data.


5 🀝 Typeclass Instances

  • Eq Script, Ord Script: based on serialized bytes for alpha-equivalence.

  • Show Script: prints <Script> placeholder.

  • Pretty via PrettyShow for wrappers.

  • Functor for applyArguments uses PLC.mkIterApp.


6 🏭 On-Chain Derivations

  • Enables embedding these types in PlutusTx code.


7 πŸ“š Glossary

  • UPLC: Untyped Plutus Core.

  • CEK: evaluation machine for Plutus Core.

  • BuiltinData: on-chain data type.

  • Script: on-chain program encoded as UPLC.

  • Validator/MintingPolicy/StakeValidator: typed script roles.

  • Datum/Redeemer/Context: inputs to validators.

  • ScriptHash/ValidatorHash/etc.: hashed identifiers for scripts.

  • CompiledCode: code produced by PlutusTx compiler plugin.

  • SerialiseViaFlat: CBOR using Flat serialization for programs.

  • ProgramSize: approximate resource usage metric.

  • Alpha-equivalence: program equality modulo renaming.

Last updated