Building plutus core

Hi there,

I was wondering if there is more info on how thee compiling of plutus scripts to plutus core is done. When I look at all examples on github [1] they are all structured the same.

  1. There is a script.hs that contains the logic for validation.
  2. There is a cabal file that says what the build is and how it is done with dependencies.
  3. There is a main.hs that compiles the script.hs to plutus core.

This is the first time I used a DSL and this way of compiling is new to me. What is unknown to me is how to setup the main.hs to correctly compile the written script to plutus core. I recognize a general structure of each of these fails in the above mentioned repository but can not extract the general way of how this works. Could someone help me with this?

The compilation to Plutus Core occurs in template Haskell code like $$(PlutusTx.compile [|| helloWorld ||]) in the script.hs files.

Serialization occurs in PlutusScriptSerialised . SBS.toShort . LBS.toStrict $ serialise helloWorldScript.

The main.hs writes the file using code like writeFileTextEnvelope filename Nothing scriptSerial. A lot of the main.hs examples do extra things like print execution units, serialize data, etc.

I don’t know of detailed documentation beside the examples and source code, but the essential, general approach is:

  1. PlutusTx.compile
  2. PlutusScriptSerialised . SBS.toShort . LBS.toStrict . serialise
  3. writeFileTextEnvelope
1 Like

Thank you! So if I am correct, the main.hs only has to execute the writeFileTextEnvelop filename Nothing scriptSerial to correctly compile the template haskell code to a serialized PlutusScriptV1. All other ectra function defined here are for debugging and statistics purposes only. This is clear!

1 Like