Skip to Content
Scalus Club is now open! Join us to get an early access to new features 🎉

Cardano Validator Types

A Cardano validator is a predicate function that approves or rejects transactions. It either succeeds (returns Unit) or fails (throws an exception). Scalus compiles Scala validators to Plutus Core bytecode.

Quick Reference

PurposeMethodValidatesCommon Use Cases
Spendingspend(...)UTxO consumptionEscrow, vesting, DEX orders
Mintingmint(...)Token creation/burningNFT collections, fungible tokens
Rewardingreward(...)Stake reward withdrawalDAO treasuries
Certifyingcertify(...)Delegation certificatesControlled delegation
Votingvote(...)Governance votesDAO voting
Proposingpropose(...)Governance proposalsTreasury limits

Creating a Validator

To create a validator, extend the Validator trait and annotate with @Compile:

@Compile object MyValidator extends Validator: inline override def spend( datum: Option[Data], redeemer: Data, tx: TxInfo, ownRef: TxOutRef ): Unit = { // validation logic here }

The @Compile annotation tells Scalus to compile your Scala code into Plutus Core bytecode.

The Validator Trait

The Validator trait is the foundation for all smart contracts. It provides methods for all six Plutus V3 script purposes:

@Compile trait Validator { inline def validate(scData: Data): Unit inline def validateScriptContext(sc: ScriptContext): Unit = { sc.scriptInfo match case ScriptInfo.MintingScript(policyId) => mint(sc.redeemer, policyId, sc.txInfo) case ScriptInfo.SpendingScript(txOutRef, datum) => spend(datum, sc.redeemer, sc.txInfo, txOutRef) case ScriptInfo.RewardingScript(credential) => reward(sc.redeemer, credential, sc.txInfo) case ScriptInfo.CertifyingScript(index, cert) => certify(sc.redeemer, cert, sc.txInfo) case ScriptInfo.VotingScript(voter) => vote(sc.redeemer, voter, sc.txInfo) case ScriptInfo.ProposingScript(index, procedure) => propose(procedure, sc.txInfo) } // Override the methods you need inline def spend(datum: Option[Data], redeemer: Data, tx: TxInfo, ownRef: TxOutRef): Unit = ??? inline def mint(redeemer: Data, policyId: PolicyId, tx: TxInfo): Unit = ??? inline def reward(redeemer: Data, stakingKey: Credential, tx: TxInfo): Unit = ??? inline def certify(redeemer: Data, cert: TxCert, tx: TxInfo): Unit = ??? inline def vote(redeemer: Data, voter: Voter, tx: TxInfo): Unit = ??? inline def propose(proposalProcedure: ProposalProcedure, tx: TxInfo): Unit = ??? }

The validate method is the entry point called by Cardano. It deserializes the script context and routes to the appropriate handler method.

Script Purposes

Spending Scripts

Most common validator type. Controls whether a UTxO can be spent.

inline override def spend( datum: Option[Data], // Data attached to the UTxO redeemer: Data, // Data provided by the spender tx: TxInfo, // Transaction script execution context ownRef: TxOutRef // Reference to the UTxO being spent ): Unit

Use cases: Escrow, vesting, multi-signature wallets, DEX order books, NFT marketplaces

Minting Policies

Governs creation and destruction of native tokens.

inline override def mint( redeemer: Data, // Data provided by the minter policyId: PolicyId, // The policy ID of tokens being minted/burned tx: TxInfo // Transaction script execution context ): Unit

Use cases: NFT collections, fungible tokens, access tokens, time-locked minting

Rewarding Scripts

Validates withdrawal of staking rewards.

inline override def reward( redeemer: Data, // Data provided by the withdrawer stakingKey: Credential, // The stake credential tx: TxInfo // Transaction script execution context ): Unit

Use cases: DAO treasury withdrawals, controlled reward distribution

Certifying Scripts

Controls publication of delegation certificates.

inline override def certify( redeemer: Data, // Data provided by the certificate publisher cert: TxCert, // The certificate being published tx: TxInfo // Transaction script execution context ): Unit

Use cases: Controlled stake delegation, DAO-managed stake pools

Voting Scripts

Validates governance votes (CIP-1694).

inline override def vote( redeemer: Data, // Data provided by the voter voter: Voter, // The voter identity tx: TxInfo // Transaction script execution context ): Unit

Use cases: DAO voting, delegated voting rights, quadratic voting

Proposing Scripts

Constitution guardrails for governance proposals.

inline override def propose( proposalProcedure: ProposalProcedure, // The proposal being submitted tx: TxInfo // Transaction script execution context ): Unit

Use cases: Treasury spending limits, parameter change constraints, protocol upgrade requirements

Next Steps

Last updated on