Why Scalus, Technically?
Why Scalus?
Scalus is a Scala 3-based Cardano DApp development platform.
I love Scala. I consider it the best programming language on the market.
It’s concise to do the proof of concept implementation. Yet it’s powerful and fast so you don’t need to rewrite your PoC when the project grows. It can be used for backend, frontend, scripting, infrastructure and Cardano smart contracts. I think it’s awesome.
With Scalus I want to give everyone the tools to do the full DApp development in Scala 3.
Here are some pros and cons.
Scala On Backend
Pros:
- you can reuse domain classes and logic between Scalus smart contracts and backend. No need to define/edit those separately, risking getting bugs.
- Scalus has integration with Bloxbean Cardano Client Lib, the defacto standard Cardano library on JVM for transaction building, used by many projects. It has similar API to Lucid.
- Scalus implements a
TransactionEvaluator
for Cardano Client Lib. This means you can measure the exact execution budgets and transaction fees for your transactions, without running a Cardano node or sending your transactions to other services. - you test your smart contracts with the exact inputs/transactions that you’ll use in production. With Aiken, all your Aiken tests are disconnected from your real transactions, thus you need to test contract logic and transactions separately, with different languages. And you can’t reuse data types for Aiken contracts and your backend/frontend code.
- you could use a typesafe frameworks to define your REST API, like Tapir
- JVM is fast. If you need some speed, JVM is still the beast.
- JVM ecosystem is immense
- compared to TypeScript you have much better language with Algebraic Data Types, pattern matching, opaque types, lazy evaluation, great composability, macros, collections, working equality, parallelism and concurrency
- compared to Rust you don’t have to deal with all those
Arc<Mutex<Box<Cell<'a, T + Sync + Clone>>>> mut &oh::my::god
; - compared to Go you have Either instead of
if err != nil
Cons:
- Go compiles faster
- Rust app starts faster
Scala On-chain
Pros:
- your contracts are in your project: no separate build/test steps
- enjoy IntelliJ Idea IDE support: navigation, refactoring that just works.
- Scala Metals LSP works in VSCode and vim as well, good enough
- DEBUGGER! It works like a charm. There is nothing even remotly close to this on Cardano
- you can reuse domain classes and logic between Scalus smart contracts and backend. No need to define/edit those separately, risking getting bugs.
- Scalus has macros that generate To/FromData instances for data types so it’s trivial to build transactions and test
- you can use Scala macros to generate and inline code
- you can use ScalaCheck, ScalaTest, MUnit or any other existing testing libraries for your contacts tests
- you can do full end-to-end testing/debugging within the same language!
- you can manipulate generated Intermediate Representation and generated UPLC if needed: apply custom simplifications, eliminate trace logging, whatever you need – all with the same language/project.
- you can create a custom, highly optimized Plutus UPLC scripts with Scalus UPLC DSL, combining manual UPLC and UPLC from Scala expressions. That’s ultimate power.
Cons:
- Scalus supports a strict subset of Scala 3 which requires some time to get use to:
- you can’t use
while
,for-comprehensions
,lazy
andtry-catch-finally
because there is no direct translation to UPLC - you can’t use any Scala function
- limited usage of pattern matching
- you can’t use
- Scalus standard library may lack functionality you might need. But we are working on it.
Scala On Frontend
Pros:
- again, you can reuse domain classes and logic if needed
- Scalus can run your V1/V2 contracts on JavaScript, both Node.js and browser.
- Scalus can calculate execution budgets on JavaScript, both Node.js and browser.
- currently, Scalus is the only library that correctly calculates execution budgets. I’ve found bugs in both Aiken and plu-ts.
- there is Laminar framework for frontend development in Scala
Cons:
- it’s far less common to use Scala on frontend, so less devs, less info
- the generated JS bundle is fairly large, ~1.5M
Support the project
Vote for our Catalyst proposals. Search for LANTR.
If you like what I’m doing, please, consider delegating your voting power to me:
CIP-105: drep1k4h4cd5jknvcfeq5uuzqthpl7sdjxrwf9gn25tdk49qxyfhusgm
CIP-129: drep1y26k7hpkj26dnp8yznnsgpwu8l6pkgcdey4zd23dk655qcse26y3g
And vote for our Catalyst proposals! Search LANTR.
Enjoy Reading This Article?
Here are some more articles you might like to read next: