Data

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

Companion object for Data providing constructors and type class instances.

Use the ToData and FromData type classes for automatic conversion between Scala types and Data.

Attributes

Companion
class
Graph
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Data.type

Members list

Type members

Classlikes

case class B(value: ByteString) extends Data

Byte string - represents binary data.

Byte string - represents binary data.

Used to encode ByteString, PubKeyHash, CurrencySymbol, TokenName, etc.

Corresponds to UPLC builtins bData and unBData.

Value parameters

value

the byte string

Attributes

Example
 B(ByteString.fromHex("deadbeef"))
 B(ByteString.empty)
Supertypes
trait Serializable
trait Product
trait Equals
class Data
class Object
trait Matchable
class Any
Show all
case class Constr(constr: BigInt, args: List[Data]) extends Data

Constructor application - represents sum types and product types.

Constructor application - represents sum types and product types.

This is the primary way to encode algebraic data types in Plutus:

  • For sum types, constr is the constructor index (0, 1, 2, ...)
  • For product types (case classes), constr is typically 0
  • args contains the constructor's field values

Corresponds to UPLC builtins constrData and unConstrData.

Value parameters

args

the constructor arguments as a list of Data values

constr

the constructor index (must be non-negative)

Attributes

Example
 // A pair (Int, String)
 Constr(0, List(I(42), B(ByteString.fromString("hello"))))
 // Either.Left(10)
 Constr(0, List(I(10)))
 // Either.Right("x")
 Constr(1, List(B(ByteString.fromString("x"))))
Supertypes
trait Serializable
trait Product
trait Equals
class Data
class Object
trait Matchable
class Any
Show all
case class I(value: BigInt) extends Data

Arbitrary-precision integer.

Arbitrary-precision integer.

Corresponds to UPLC builtins iData and unIData.

Value parameters

value

the integer value

Attributes

Example
 I(42)
 I(-1000000000000000000L)
Supertypes
trait Serializable
trait Product
trait Equals
class Data
class Object
trait Matchable
class Any
Show all
case class List(values: List[Data]) extends Data

Ordered sequence - represents list types.

Ordered sequence - represents list types.

Used to encode List[A] types where elements are Data.

Corresponds to UPLC builtins listData and unListData.

Value parameters

values

the list elements

Attributes

Example
 // A list of integers [1, 2, 3]
 List(PList(I(1), I(2), I(3)))
Supertypes
trait Serializable
trait Product
trait Equals
class Data
class Object
trait Matchable
class Any
Show all
case class Map(values: List[(Data, Data)]) extends Data

Key-value mapping - represents associative data structures.

Key-value mapping - represents associative data structures.

Used to encode Map[K, V] types where both keys and values are Data. Note that duplicate keys are allowed (this is a list of pairs, not a true map).

Corresponds to UPLC builtins mapData and unMapData.

Value parameters

values

list of key-value pairs

Attributes

Example
 // A map from integers to strings
 Map(List((I(1), B(hex"aa")), (I(2), B(hex"bb"))))
Supertypes
trait Serializable
trait Product
trait Equals
class Data
class Object
trait Matchable
class Any
Show all

Inherited classlikes

object dataCborDecoder extends Decoder[Data]

CBOR decoder for the Data type. The encoding and decoding logic is based on the Cardano node implementation.

CBOR decoder for the Data type. The encoding and decoding logic is based on the Cardano node implementation.

Attributes

Inherited from:
DataApi (hidden)
Supertypes
trait Decoder[Data]
class Object
trait Matchable
class Any
object dataCborEncoder extends Encoder[Data]

CBOR encoder for the Data type. The encoding and decoding logic is based on the Cardano node implementation.

CBOR encoder for the Data type. The encoding and decoding logic is based on the Cardano node implementation.

Attributes

Inherited from:
DataApi (hidden)
Supertypes
trait Encoder[Data]
class Object
trait Matchable
class Any
object given_Flat_Data extends Flat[Data]

Attributes

Inherited from:
DataApi (hidden)
Supertypes
trait Flat[Data]
class Object
trait Matchable
class Any
object given_Pretty_Data extends Pretty[Data]

Pretty prints Data in debug format with rainbow brackets: <constr, [args]>, {k: v}, [v], 123, "hex"

Pretty prints Data in debug format with rainbow brackets: <constr, [args]>, {k: v}, [v], 123, "hex"

Attributes

Inherited from:
DataApi (hidden)
Supertypes
trait Pretty[Data]
class Object
trait Matchable
class Any

Types

type FromData[A] = FromData[A]

Type class for converting Data back to typed values.

Type class for converting Data back to typed values.

Attributes

type ToData[A] = ToData[A]

Type class for converting values to Data representation.

Type class for converting values to Data representation.

Attributes

Inherited and Abstract types

type MirroredElemLabels <: Tuple

The names of the product elements

The names of the product elements

Attributes

Inherited from:
Mirror
type MirroredLabel <: String

The name of the type

The name of the type

Attributes

Inherited from:
Mirror

Value members

Concrete methods

inline def fromData[A](inline data: Data)(using inline ev: FromData[A]): A

Converts Data to type A using the FromData type class.

Converts Data to type A using the FromData type class.

Value parameters

data

the Data to convert

Attributes

Returns

the converted value

Throws
Exception

if the Data structure doesn't match the expected type

Inherited methods

Decode a Data value from CBOR

Decode a Data value from CBOR

Attributes

Inherited from:
DataApi (hidden)
def fromCbor(is: InputStream): Data

Decode a Data value from CBOR

Decode a Data value from CBOR

Attributes

Inherited from:
DataApi (hidden)
def fromCbor(bytes: Array[Byte]): Data

Decode a Data value from CBOR

Decode a Data value from CBOR

Attributes

Inherited from:
DataApi (hidden)
def fromJson(json: String): Data

Decode a Data value from JSON

Decode a Data value from JSON

Attributes

Inherited from:
DataApi (hidden)
def toJson(data: Data, indent: Int = ...): String

Encode a Data value to JSON

Encode a Data value to JSON

Attributes

Inherited from:
DataApi (hidden)
def tryFromData[T](d: Data)(using fd: FromData[T]): Try[T]

Tries to decode a value of type T from Data

Tries to decode a value of type T from Data

Attributes

Returns

Success(value) if decoding was successful, Failure(exception) otherwise

Inherited from:
DataApi (hidden)

Concrete fields

val unit: Data

The unit value encoded as Data.

The unit value encoded as Data.

Equivalent to Constr(0, Nil) - an empty constructor with tag 0.

Attributes

Givens

Inherited givens

given DataReadWriter: ReadWriter[Data]

JSON ReadWriter for the Data type.

JSON ReadWriter for the Data type.

Attributes

Inherited from:
DataApi (hidden)

CBOR decoder for the Data type. The encoding and decoding logic is based on the Cardano node implementation.

CBOR decoder for the Data type. The encoding and decoding logic is based on the Cardano node implementation.

Attributes

Inherited from:
DataApi (hidden)

CBOR encoder for the Data type. The encoding and decoding logic is based on the Cardano node implementation.

CBOR encoder for the Data type. The encoding and decoding logic is based on the Cardano node implementation.

Attributes

Inherited from:
DataApi (hidden)

Attributes

Inherited from:
DataApi (hidden)

Pretty prints Data in debug format with rainbow brackets: <constr, [args]>, {k: v}, [v], 123, "hex"

Pretty prints Data in debug format with rainbow brackets: <constr, [args]>, {k: v}, [v], 123, "hex"

Attributes

Inherited from:
DataApi (hidden)

Extensions

Extensions

extension [A](a: A)
inline def toData: Data

Converts this value to its Data representation using the ToData type class.

Converts this value to its Data representation using the ToData type class.

Attributes

extension (inline data: Data)
inline def to[A](using inline ev: FromData[A]): A

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

Inherited extensions

extension [A <: Data](a: A)(implicit evidence$1: Writer[A])
inline def toJsonIndented: String

Encode a Data value to indented JSON

Encode a Data value to indented JSON

Attributes

Inherited from:
DataApi (hidden)
extension [A <: Data](a: A)
inline def toJson: String

Encode a Data value to JSON

Encode a Data value to JSON

Attributes

Inherited from:
DataApi (hidden)
extension [A <: Data](a: A)
def toCbor: Array[Byte]

Encode a Data value to CBOR.

Encode a Data value to CBOR.

Attributes

Inherited from:
DataApi (hidden)

Encode a Data value to CBOR ByteString

Encode a Data value to CBOR ByteString

Attributes

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

Attributes

Inherited from:
DataApi (hidden)
inline def toB: ByteString

Attributes

Inherited from:
DataApi (hidden)
inline def toBigInt: BigInt

Attributes

Inherited from:
DataApi (hidden)
inline def toByteString: ByteString

Attributes

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

Attributes

Inherited from:
DataApi (hidden)
inline def toI: BigInt

Attributes

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

Attributes

Inherited from:
DataApi (hidden)

Attributes

Inherited from:
DataApi (hidden)
extension (self: Data)
inline def dataHash: ByteString

Attributes

Inherited from:
DataApi (hidden)