Data

scalus.uplc.builtin.Data
See theData companion object
sealed abstract class Data

The universal data type for Plutus smart contracts.

Data is the core serializable type used throughout Cardano for representing:

  • Script datums attached to UTxOs
  • Redeemers passed to validators
  • Arbitrary structured data in smart contracts

It corresponds to the BuiltinData type in Plutus Core and can represent any algebraic data type through its five constructors:

  • Data.Constr - Constructor application with tag and arguments (for sum/product types)
  • Data.Map - Key-value mappings
  • Data.List - Ordered sequences
  • Data.I - Arbitrary-precision integers
  • Data.B - Byte strings

==Encoding Convention==

Scalus uses the standard Plutus Data encoding:

  • Sum types use Constr with constructor index as tag
  • Product types (case classes) use Constr with fields as arguments
  • Option[A] encodes as Constr(0, []) for None, Constr(1, [value]) for Some
  • Boolean encodes as Constr(0, []) for false, Constr(1, []) for true

==UPLC Builtin Operations==

The following UPLC builtins operate on Data:

  • chooseData - Pattern match on Data constructor
  • constrData, mapData, listData, iData, bData - Construct Data values
  • unConstrData, unMapData, unListData, unIData, unBData - Deconstruct Data values
  • equalsData - Structural equality comparison
  • serialiseData - CBOR serialization (Plutus V2+)

Attributes

See also

scalus.uplc.builtin.ToData for automatic encoding to Data

scalus.uplc.builtin.FromData for automatic decoding from Data

Example
 // Encoding a simple value
 val intData: Data = Data.I(42)
 // Encoding a product type (pair)
 val pairData: Data = Data.Constr(0, List(Data.I(1), Data.I(2)))
 // Encoding a sum type (Option)
 val someData: Data = Data.Constr(1, List(Data.I(42)))  // Some(42)
 val noneData: Data = Data.Constr(0, List.Nil)          // None
Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class B
class Constr
class I
class List
class Map

Members list

Value members

Concrete methods

inline def to[A](using inline ev: FromData[A]): A
Extension method from Data

Converts this Data to type A using the FromData type class.

Converts this Data to type A using the FromData type class.

Attributes

Throws
Exception

if the Data structure doesn't match the expected type

override def toString: String

Debug string representation matching the Pretty instance format. It does not recurse, so the nesting depth is not limited by the stack.

Debug string representation matching the Pretty instance format. It does not recurse, so the nesting depth is not limited by the stack.

Attributes

Definition Classes
Any

Inherited methods

inline def dataHash: ByteString
Extension method from Data

Attributes

Inherited from:
DataApi (hidden)
inline def field[A](inline expr: A => Any): Data
Extension method from Data

Attributes

Inherited from:
DataApi (hidden)
inline def toB: ByteString
Extension method from Data

Attributes

Inherited from:
DataApi (hidden)
inline def toBigInt: BigInt
Extension method from Data

Attributes

Inherited from:
DataApi (hidden)
inline def toByteString: ByteString
Extension method from Data

Attributes

Inherited from:
DataApi (hidden)
inline def toConstr: BuiltinPair[BigInt, BuiltinList[Data]]
Extension method from Data

Attributes

Inherited from:
DataApi (hidden)
inline def toI: BigInt
Extension method from Data

Attributes

Inherited from:
DataApi (hidden)
inline def toList: BuiltinList[Data]
Extension method from Data

Attributes

Inherited from:
DataApi (hidden)
Extension method from Data

Attributes

Inherited from:
DataApi (hidden)