Plutus Core Builtin Functions Reference

This document serves as a reference to the Plutus Core builtin functions, aka DefaultFun. It is primarily meant for Pluto users and Plutarch developers/contributors. As such, it contains information about forcing. That is, how many times each of these builtins need to be forced to actually use them.

Note: If you spot any mistakes/have any related questions that this guide lacks the answer to, please don’t hesitate to raise an issue. The goal is to have high quality documentation for Pluto and Plutarch users!

Cross Reference

Note: The “Type” column of the table below is primarily for documentation reasons. After all, it’s all Untyped Plutus Core. However, most of these types do need to be adhered to. There are a few cases where some flexibility allowed. These cases will be noted on the table itself.

Note: For brevity, BuiltinType is referred to just Type in the table. So Integer actually refers to BuiltinInteger. BuiltinUnit is written as ().

Note: Plutarch either provides direct synonyms to these builtin functions, or provides a safer wrapper around them. Consult the Plutarch guide. However, if you must to use the builtins directly in Plutarch, see Plutus Core Builtins section on the Plutarch guide.

DefaultFunTypeForcesDescriptionPluto Usage
AddIntegerInteger -> Integer -> Integer0Sum 2 integers and return the result.AddInteger 1 2 -- 3
SubtractIntegerInteger -> Integer -> Integer0Subtract fist integer by second and return the result.SubtractInteger 5 2 -- 3
MultiplyIntegerInteger -> Integer -> Integer0Multiply 2 integers and return the result.MultiplyInteger 3 3 -- 9
DivideIntegerInteger -> Integer -> Integer0Divide first integer by second and return the result.DivideInteger 6 2 -- 3
QuotientIntegerInteger -> Integer -> Integer0Quotient of first integer by second and return the result.QuotientInteger 5 2 -- 2
RemainderIntegerInteger -> Integer -> Integer0Remainder of first integer by second and return the result.RemainderInteger 5 2 -- 1
ModIntegerInteger -> Integer -> Integer0Modulus of first integer by second and return the result.ModInteger 5 2 -- 1
EqualsIntegerInteger -> Integer -> Bool0Equality between two integers.EqualsInteger 1 1 -- True
LessThanIntegerInteger -> Integer -> Bool0LT comparison between two integers.LessThanInteger 1 3 -- True
LessThanEqualsIntegerInteger -> Integer -> Bool0LTE comparison between two integers.LessThanEqualsInteger 1 1 -- True
AppendByteStringByteString -> ByteString -> ByteString0Concatenate two bytestrings.AppendByteString 0xfe 0xab -- 0xfeab
ConsByteStringInteger -> ByteString -> ByteString0Prepend a byte, represented by a natural number (Integer), to a bytestring.ConsByteString 65 0xab -- 0x41ab
SliceByteStringInteger -> Integer -> ByteString -> ByteString0Slice a bytestring using given indices (inclusive on both ends).SliceByteString 1 3 0x4102afde5b2a -- 0x02afde
LengthOfByteString1ByteString -> Integer0Get the length of a bytestring.LengthByteString 0x4102afde5b2a -- 6
IndexByteStringByteString -> Integer -> Integer0Get the byte at given index from a bytestring.IndexByteString 0x4102afde5b2a 2 -- 175
EqualsByteStringByteString -> ByteString -> Bool0Equality between two bytestrings.EqualsByteString 0xab 0xab -- True
LessThanByteStringByteString -> ByteString -> Bool0LT comparison between two bytestrings.LessThanByteString 0x10 0xab -- True
LessThanEqualsByteString2ByteString -> ByteString -> Bool0LTE comparison between two bytestrings.LessThanEqualByteString 0x10 0x10 -- True
Sha2_256ByteString -> PByteString0Hash a bytestring using SHA-256.
Sha3_256ByteString -> PByteString0Hash a bytestring using SHA3-256.
Blake2b_256ByteString -> ByteString0Hash a bytestring using Blake2B-25.
VerifySignatureByteString :--> ByteString :--> ByteString :--> PBool0Given PubKey, Message, and Signature, verify the signature.
AppendStringString -> String -> String0Concatenate two strings/texts.AppendString "foo" "bar" -- "foobar"
EqualsStringString -> String -> Bool0Equality between two strings/texts.EqualsString "foo" "foo" -- True
EncodeUtf8String -> ByteString0Encode a string/text using UTF-8.
DecodeUtf8ByteString -> String0Decode a bytestring using UTF-8.
IfThenElseBool -> a -> a -> a31if-then-else as a function. Both branches are strictly evaluated, since UPLC is strict.! IfThenElse True 42 7 -- 42
ChooseUnit() -> a -> a1“Choose” (catamorphism) on the unit type. Since the unit type has only one representation - it just has one branch.! ChooseUnit () 42 -- 42
TraceString -> a -> a1Log the message given by the first argument and return the second argument.! Trace "foo" 1 -- 1
FstPairPair a b -> a2Get the first member of the pair.! ! FstPair (MkPairData (data 1) (data [42, 0xfe])) -- data 1
SndPairPair a b -> a2Get the second member of the pair.! ! SndPair (MkPairData (data 1) (data [42, 0xfe])) -- data [42, 0xfe]
ChooseListList a -> b -> b -> b32“Choose” (catamorphism) on a builtin list. Return the second argument if list was empty/nil, otherwise return the third argument. As usual, both arguments are evaluated before choosing.! ! ChooseList (MkNilData ()) 0x41 0xab -- 0x41
MkConsa -> List a -> List a1Prepend an element onto a list. The list element type must be the same as the 1st arg type.! MkCons (data 1) (MkNilData ()) -- [data 1]
HeadListList a -> a1Get the first element of a list. Errors if list is empty.! HeadList (! MkCons (data 1) (MkNilData ())) -- data 1
TailListList a -> List a1Get the tail of a list (i.e everything but the first element). Errors if list is empty.! TailList (! MkCons (data 1) (MkNilData ())) -- []
NullListList a -> Bool1Returns True if given list is empty.! NullList (MkNilData ())
ChooseDataData -> a -> a -> a -> a -> a -> a31“Choose” (catamorphism) on Data. It has 5 branches. The first branch (second argument) is returned for Constr, the second branch for Map, the third for List, the fourth for I, and finally, the fifth for B. As usual, all arguments are evaluated before choosing.! ChooseData (data 0xbc) 0 1 2 3 4 -- 4
ConstrDataInteger -> List Data -> Data0Create a Constr data with a constructor id and its fields, as a builtin list of Data elements.Constrdata 0 (MkNilData ()) -- data sigma0.[]
MapDataList (Pair Data Data) -> Data0Wrap a bytestring into a Data. Returns a B data value.MapData (MkNilPairData ()) -- data {}
ListDataList Data -> Data0Wrap a builtin list of Data elements into a Data. Returns a List data value.ListData (! MkCons (data 1) (MkNilData ())) -- data [1]
IDataInteger -> Data0Wrap an integer into a Data. Returns a I data value.IData 42 -- data 42
BDataByteString -> Data0Wrap a bytestring into a Data. Returns a B data value.BData 0xab -- data 0xab
UnConstrDataData -> Pair Integer (List Data)0Get the constructor id and the fields in a pair from a Constr data value. Fails if the Data isn’t a Constr data.UnConstrData (data sigma0.[]) -- (0, [])
UnMapDataData -> List (Pair Data Data)0Extract a List (Pair Data Data) from a Map data value. Fails if the Data isn’t a Map data.UnMapData (data { 0xab = 1 }) -- [(0xab, 1)]
UnListDataData -> List Data0Extract a List Data from a List data value. Fails if the Data isn’t a List data.UnListData (data [1]) -- [data 1]
UnIDataData -> Integer0Extract a Integer from a I data value. Fails if the Data isn’t a I data.UnIData (data 42) -- 42
UnBDataData -> ByteString0Extract a ByteString from a B data value. Fails if the Data isn’t a B data.UnBData (data 0xab) -- 0xab
EqualsDataData -> Data -> Bool0Equality between two data values.EqualsData (data [5, 0xab]) (data [5, 0xab]) -- True
MkPairDataData -> Data -> Pair Data Data0Make a pair of Data values.MkPairData (data 1) (data [42, 0xfe]) -- (data 1, data [42, 0xfe])
MkNilData() -> List Data0Make a nil list of Data.MkNilData () -- []
MkNilPairData() -> List (Pair Data Data)0Make a nil list of Pair Data Data.MkNilPairData () -- []

1: LengthOfByteString is called LengthByteString in Pluto.

2: LessThanEqualsByteString is called LessThanEqualByteString in Pluto.

3: This can actually take in different types for its branches. The type of one branch could be Integer, whereas the other could be Data, and so on.

Useful Links

Links to this page