A minimal Scalus smart contract, generated from the hello.g8 template.
HelloCardano.scala is a Plutus V3 spending validator that approves spending a UTxO only when the
transaction is both signed by the owner stored in the datum and carries the redeemer string
"Hello, Cardano!".
The project works with both Scala CLI and sbt.
With Scala CLI:
scala-cli test .
scala-cli compile .
scala-cli fmt .With sbt:
sbt test
sbt compileBoth tools share the same flat source layout: sources live at the project root and test
sources use the .test.scala suffix.
HelloCardanoIntegration.test.scala runs against a backend selected by the SCALUS_TEST_ENV
environment variable:
sbt test # in-memory emulator (default, fast)
SCALUS_TEST_ENV=yaci sbt test # a local Yaci DevKit node (requires a running Docker daemon)The same works with Scala CLI, e.g. SCALUS_TEST_ENV=yaci scala-cli test ..
The sbt build enables the scalus-sbt-plugin, which adds tasks
backed by the Contract in HelloCardanoContract.scala:
# Generate a CIP-57 blueprint at
# target/scala-3.3.7/classes/META-INF/scalus/blueprints/HelloCardanoContract.json
sbt blueprint
# Deploy the validator as a reference-script UTxO (needs a Blockfrost key and a funded wallet)
export BLOCKFROST_API_KEY=... # or pass --blockfrost-key
export CARDANO_MNEMONIC="word1 ..." # or pass --mnemonic
sbt "deploy HelloCardanoContract --network preview"Set SCALUS_PROFILE=1 to run the tests with on-chain execution profiling enabled. It writes an
interactive HTML profile (CPU/memory per source line) to target/profile.html:
SCALUS_PROFILE=1 sbt testThe same works with Scala CLI, e.g. SCALUS_PROFILE=1 scala-cli test ..
- Scalus documentation: https://scalus.org
- Examples: https://github.com/nau/scalus/tree/master/scalus-examples