I’m still in the early stages of learning how to build Plutus smart contracts and am realizing I need a better understanding of working with Haskell, particularly in forming the proper environment files for a project. For example, I create a new project, run cabal init, then begin coding, lets say a simple validator…at that point how do I do the following (without manually or copy/pasting if possible):
Update the cabal.project file to reflect the appropriate dependency sources
Update the .cabal file
Update the app/ .hs file to output my .plutus script
I’m specifically talking about compilation on my local system, not the playground, I want to be able to effectively compile validator scripts which I can immediately test on the testnet.
I’ve not found a clear tutorial on these low level tasks, if someone can point me to a crash course on this portion or similar documentation as it relates to compiling plutus files, that would be so helpful!
Regarding cabal.project, the Cardano and Plutus package dependencies are rather complex, so it is best to start with a copy of that file that is known to have compatible dependencies for generating Plutus that runs on cardano-node-1.29.0. If the additional packages that you’re using are all on Hackage, then you probably won’t need to edit cabal.project further, since the Hackage packages will resolve during cabal configure or cabal build. If the additional packages aren’t in Hackage, then you’ll need to add entries to cabal.project.
An idealized version of my typical workflow for a new Plutus project is:
Run cabal init and edit the .cabal file for the project if needed.
Grab cabal.project for the appropriate tag on the cardano-node repository, and then add an entry to that for cardano-node itself.
Write the Haskell code.
Add dependencies for any new import statements to the .cabal files. If those dependencies aren’t in Hackage, then also add them to cabal.project.
Build with cabal build.
Run the executable directly or use cabal run to compile and serialize the Plutus script.
Use cardano-cli to use the script on testnet.
Iterate steps 3-7.
I say “idealized” because I’ll typically add the dependencies before writing any code so then my IDE (VIM+HLS+hlint+…) assists. Also, I generally use haskell.nix and nix-shell to create a releases and/or a development environment. I’ll also use off-chain Haskell instead of cardano-cli.
This is a fantastic workflow. Thank you for sharing this, maybe the type of learner I am but nowhere could I find a simple outline/workflow scaffolding like you just provided!
Note: Yes I have been working with the Alonzo-testnet repo but I believe I had an outdated version or at least my cabal.project file I cloned def had outdated tags. Will be cleaning up my environment lol.
Update: @bwbush I was able to successfully compile down to a plutus script (finally), thank you again for your help!