Plutus.V1.Ledger.Address
1. π Overview
2. π§ Language Extensions and Imports
3. ποΈ Data Structures
3.1 π newtype Example
3.2 π€ type Synonym Example
3.3 π¦ data Type Example
3.4 π Address Data Type
4. βοΈ Functions
4.1 π pubKeyHashAddress
4.2 π toPubKeyHash
4.3 π toValidatorHash
4.4 π·οΈ scriptHashAddress
4.5 π° stakingCredential
5. π€ Typeclass Instances
6. π Glossary
1 π Overview
This tutorial walks through a Plutus Address script in Haskell:
Defines a custom
Addressdata type with payment and staking credentials.Implements helper functions to build and query addresses.
Shows how to derive instances for on-chain data (
IsData) and lifting.Explains language extensions, imports, and related typeclasses.
It also illustrates basic newtype, type synonym, and data definitions for comparison.
2 π§ Language Extensions and Imports
DerivingStrategies: chooses between
stockandanyclassfor deriving.DeriveAnyClass: allows deriving classes like
NFData.TemplateHaskell: used by
PlutusTx.makeIsDataIndexedandmakeLiftfor on-chain code.OverloadedStrings: for convenient string literals in
Prettyprinter.INLINABLE pragma**: marks functions for on-chain compilation and optimization.
Imports:
NFData, Generic: for strict evaluation and generic deriving.
PlutusTx modules: on-chain utilities (
Bool,Eq,makeIsDataIndexed,makeLift).Prettyprinter: for human-readable
Prettyinstance.Ledger.Credential, Crypto, Scripts: on-chain ledger types (
PubKeyHash,ValidatorHash,Credential).
3 ποΈ Data Structures
Below are examples of the three Haskell type definitions, followed by our Address.
3.1 π newtype Example
Inputs:
IntvalueProcessing: none (zero-cost wrapper)
Output:
MyInt
3.2 π€ type Synonym Example
Inputs/Outputs: identical to
String, just renamed.
3.3 π¦ data Type Example
Inputs:
DoubleparametersProcessing: none at construction
Outputs:
Shapevalue
3.4 π Address Data Type
Fields:
addressCredential: on-chainCredential(either a public key or script)addressStakingCredential: optionalStakingCredential
Derivations:
Eq,Ord,Show,GenericviastockNFDataviaanyclass
Example Usage:
4 βοΈ Functions
Each function below is marked {-# INLINABLE #-} for on-chain use.
4.1 π pubKeyHashAddress
Inputs:
PubKeyHashProcessing: wraps into
PubKeyCredential, sets no stakingOutput:
Address
Example:
4.2 π toPubKeyHash
Inputs:
AddressProcessing: pattern match on
CredentialOutput:
Maybe PubKeyHash
Examples:
4.3 π toValidatorHash
Inputs:
AddressProcessing: pattern match on
ScriptCredentialOutput:
Maybe ValidatorHash
Example:
4.4 π·οΈ scriptHashAddress
Inputs:
ValidatorHashProcessing: wraps into
ScriptCredential, no stakingOutput:
Address
Example:
4.5 π° stakingCredential
Inputs:
AddressProcessing: field projection
Output:
Maybe StakingCredential
Example:
5 π€ Typeclass Instances
Class:
PrettyfromPrettyprinterMethod:
pretty :: a -> Doc annBehavior: prints the payment credential and staking in parentheses.
Class:
EqfromPlutusTx, used on-chainMethod:
(==)must beINLINABLE
On-chain Derivation:
makeIsDataIndexed: generates
IsDatainstance with constructor indexmakeLift: allows lifting Haskell values into on-chain code
6 π Glossary
Address: On-chain identifier combining payment & staking credentials.
Credential: Either
PubKeyCredential PubKeyHashorScriptCredential ValidatorHash.StakingCredential: Optional credential for staking rewards.
PubKeyHash: Hash of a public key.
ValidatorHash: Hash of a validator script.
INLINABLE: GHC pragma making function available for specialization.
makeIsDataIndexed: Template Haskell for on-chain data serialization.
makeLift: Template Haskell for lifting to on-chain.
newtype: Zero-cost wrapper around a single field type.
type: Synonym for another type.
data: Defines a new algebraic data type.
NFData: Class for deep evaluation (
rnf).Pretty: Class for pretty-printing values.
Last updated