Getting Started with Scalus
This guide will help you set up your Scalus development environment and create your first Cardano validator in minutes. You’ll install Scala 3, generate a starter project, and run your first smart contract tests.
Install Scala 3 Development Environment
We recommend using Coursier , the official Scala installer that sets up your complete development environment including JVM, Scala compiler, build tools, and code formatters.
macOS - Brew
Homebrew based installation:
brew install coursier && coursier setupCoursier will install Scala compiler, Command line tool: Scala CLI , Build tool: sbt , REPL: Ammonite and Code formatter: Scalafmt .
Get Your First Cardano Validator
sbt new scalus3/hello.g8This ran the template scalus3/hello.g8 using Giter8 . Let’s take a look at what just got generated:
validator/
├── HelloCardano.scala # Simple validator
├── HelloCardano.test.scala # Simple tests
├── project.scala # Project configuration
└── README.mdRun Your First Validator Tests
Run unit tests (MUnit, ScalaTest and ScalaCheck):
scala-cli test helloAll is good if you see the following output:
HelloCardanoTest:
- Hello Cardano message is signed by the ownerSet Up Your IDE for Cardano Development
Setting up a productive development environment will significantly improve your Scala/Scalus development experience. Scala offers wide range of IDE support, the most popular are IntelliJ and VSCode.
IntelliJ
- Install IntelliJ IDEA (Community or Ultimate edition) from the JetBrains websiteÂ
- Install the Scala plugin:
- Go to Settings/Preferences → Plugins → Marketplace
- Search for “Scala” and install the plugin
- Restart IntelliJ IDEA when prompted
- Open your Scalus project:
- Select File → Open and navigate to your project directory
- Choose Import as sbt project when prompted
You are good to go! Start exploring.
import scalus.*
import scalus.builtin.Data
import scalus.ledger.api.v3.{PubKeyHash, TxInfo, TxOutRef}
import scalus.prelude.*
/** This validator demonstrates two key validation checks:
* 1. It verifies that the transaction is signed by the owner's public key hash (stored in the datum)
* 2. It confirms that the redeemer contains the exact string "Hello, Cardano!"
*
* Both conditions must be met for the validator to approve spending the UTxO.
*/
@Compile
object HelloCardano extends Validator:
inline override def spend(
datum: Option[Data],
redeemer: Data,
tx: TxInfo,
outRef: TxOutRef
): Unit =
val owner = datum.getOrFail("Datum not found").to[PubKeyHash]
val signed = tx.signatories.contains(owner)
require(signed, "Must be signed")
val saysHello = redeemer.to[String] == "Hello, Cardano!"
require(saysHello, "Invalid redeemer")Next Steps
Now that you have your development environment set up and a working validator, continue your Scalus journey:
- Learn Smart Contract Development - Deep dive into writing Cardano validators with Scala 3, understanding the compilation process, and leveraging the Scalus type system
- Build and Submit Transactions - Use TxBuilder to construct transactions, evaluate scripts off-chain, and submit them to the Cardano network
New to Cardano or Scala? Check out our onboarding guides for developers coming from either ecosystem.