Plutus : Plutus.V1.Ledger Essentials

📌 Table of Contents

  1. 📁 What Is Plutus.V1.Ledger?

  2. 🧱 Core Modules Breakdown

  3. 📬 Working with Addresses

  4. 🔐 Working with Signatures & Keys

  5. 💰 Working with Values

  6. 🧾 Working with Transactions

  7. 🧪 Script Contexts & Purpose

  8. 🛠 Utilities (Time, Interval, etc.)

  9. 🧠 Glossary of Terms

  10. 🧪 Validator Script Examples

  11. 🔧 Typed Validator Wrappers

  12. 🧪 Emulator Trace Integration


1️⃣ 📁 What Is Plutus.V1.Ledger?

Plutus.V1.Ledger is a collection of types and utilities from the Plutus smart contract platform used to build secure, type-safe smart contracts for Cardano. It includes definitions for:

  • Addresses

  • Transactions

  • Values

  • Script contexts

  • Signatures and more


2️⃣ 🧱 Core Modules Breakdown

Module
Purpose

Address

Work with Cardano addresses

Value

Represent and manipulate tokens

Tx, TxInfo

Transaction and transaction context

Scripts, ScriptContext

For writing validators

Contexts

Access to signatures, redeemers, datums

Interval, Slot, Time

Handling time and validity ranges


3️⃣ 📬 Working with Addresses

  • Address is either a public key hash or a script hash.

  • Use scriptHashAddress to create an address from a validator script hash.


4️⃣ 🔐 Working with Signatures & Keys

  • PubKeyHash: Identifies wallets.

  • txSignedBy :: TxInfo -> PubKeyHash -> Bool checks if a transaction is signed by a given key.


5️⃣ 💰 Working with Values

  • Value is a map of CurrencySymbol -> TokenName -> Amount.

  • Use singleton to construct a token bundle:

  • Combine values using +, -, or valueOf.


6️⃣ 🧾 Working with Transactions

  • TxInfo gives all information about the transaction.

  • Key fields:

    • txInfoInputs, txInfoOutputs

    • txInfoSignatories

    • txInfoValidRange

Use it in validators:


7️⃣ 🧪 Script Contexts & Purpose

  • ScriptContext: Execution context of a Plutus script.

  • ScriptPurpose: Why the script is running (e.g., Spending, Minting).

  • Access redeemer with findOwnInput, findDatum, etc.


8️⃣ 🛠 Utilities (Time, Interval, etc.)

  • Use POSIXTime and POSIXTimeRange for timelocks.

  • Example:


9️⃣ 🧠 Glossary of Terms

Term
Description

Address

Script or wallet hash for locking funds

Value

Multi-asset bundle of tokens

TxInfo

Transaction information (inputs, signers, outputs)

ScriptContext

Runtime context passed to validators

PubKeyHash

Hash of wallet public key

CurrencySymbol

Identifier for a token type

TokenName

Token label (e.g., "MyCoin")

POSIXTime

UTC time representation

Validator

Script that determines if a transaction is allowed


🔟 🧪 Validator Script Examples

🔐 Signature Check Validator

⏰ Timelock Validator

💸 Minimum ADA Sent to Address


1️⃣1️⃣ 🔧 Typed Validator Wrappers


1️⃣2️⃣ 🧪 Emulator Trace Integration

Use this with endpoints for lock/spend via submitTxConstraints.


✅ Summary

The Plutus.V1.Ledger module is your toolkit for interacting with the Cardano ledger when writing smart contracts. It provides powerful primitives to:

  • Read transaction data

  • Check authorization

  • Work with tokens and addresses

  • Enforce timelocks and intervals

Last updated