Skip to Content
Scalus Club is now open! Join us to get an early access to new features 🎉
DocumentationTransactions

Building Cardano Transactions

Scalus provides a fluent API for constructing Cardano transactions — payments, token minting, staking, governance, and smart contract interactions.

What You Can Build

Transaction Builder

TransactionBuilder (TxBuilder) handles the complexity of Cardano transactions — UTxO selection, fee calculation, script evaluation, and balancing:

val tx = TxBuilder(env) .payTo(recipient, Value.ada(10)) .complete(provider, myAddress) .await() .sign(signer) .transaction

Since validators are written in Scala, you can share code between on-chain and off-chain:

  • Code Reuse — Share data types and validation logic
  • Type Safety — Scala’s type system across your entire stack
  • Integrated Testing — Test validators and transactions together

Quick Example

val tx = TxBuilder(env) .spend(utxo) // Add UTxO as input .payTo(recipientAddress, Value.ada(10)) // Send 10 ADA to recipient .build(changeTo = changeAddress) // Finalize: calculate fees, handle change .sign(signer) // Add signature .transaction // Get the final transaction

TxBuilder is purely functional — each method returns a new immutable instance. Only build() can throw while evaluating scripts and balancing.

Automatic Completion

The complete() method handles everything that can be determined programmatically:

TxBuilder(env) .payTo(recipient, Value.ada(10)) .complete(provider, sponsorAddress) // Automatically complete using funds from sponsorAddress

It automatically:

  • Selects UTxOs from the sponsor address to cover outputs and fees
  • Adds collateral inputs for script execution
  • Calculates fees based on transaction size and execution costs
  • Creates change outputs and iteratively rebalances

Script Evaluation

TxBuilder evaluates Plutus scripts during build to catch errors before submission:

TxBuilder(env, evaluator) .spend(scriptUtxo, redeemer, script) .payTo(recipient, scriptUtxo.output.value) .build(changeTo = changeAddress) // Scripts evaluated here

Next Steps

Last updated on