Plutus scripts

Cardano uses scripts to validate actions. These scripts, which are pieces of code, implement pure functions with True or False outputs. Script validation is the process of invoking the script interpreter to run a given script on appropriate arguments.

What are scripts?

A script is a program that decides whether the transaction that spends the output is authorized to do so. Such a script is called a validator script – it validates whether the spending is allowed.

As an example, a simple validator script could check whether a particular key signed the spending transaction – this would exactly replicate the behavior of the simpler pay-from-pubkey outputs. However, with a bit of careful extension, we can use scripts to express more useful logic on the chain than that.

The way the EUTXO model works is that validator scripts are passed as three arguments:

  1. Datum: this is a piece of data attached to the output that the script is locking. This is typically used to carry state.
  2. Redeemer: this is a piece of data attached to the spending input. This is typically used to provide an input to the script from the spender.
  3. Context: this is a piece of data that represents information about the spending transaction. This is used to make assertions about the way the output is being sent (such as “Bob signed it”).

The data contained in the context is:

  • inputs – outputs to be spent
  • reference inputs – inputs used for reference only, they are not spent
  • outputs – new outputs created by the transaction
  • fees – transaction fees
  • minted value – minted or burned value
  • certificates – digest of certificates contained in the transaction
  • withdrawals – used to withdraw rewards from the stake pool
  • valid range – a range of time in which the transaction is valid
  • signatories – a list of transaction signatures
  • redeemers – data used to provide an input to the script from the spender
  • info data – a map of datum hashes to their datum value
  • id – transaction identification

Script tutorials and examples

Cost model parameters

The cost model for Plutus Core scripts has several parameters, which are part of the Cardano protocol parameters.

See the following for more details: