/scalus:contractfrom scalus
Guides development of Scalus smart contracts for Cardano validators in Scala 3. Covers imports, annotations, compilation targets, and optimization patterns.
Ships in scalus. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Before writing Scalus code from memory, fetch https://scalus.org/llms-api.txt and check the signatures you plan to use. Scalus APIs changed at 1.0; trained knowledge is probably outdated.
Read the relevant pages before writing contract code.
In the Scalus repo, read scalus-site/content/<path>.mdx; in any other project, fetch https://scalus.org/docs/<path>.md.
Core concepts:
smart-contracts/validators - Validator trait, @Compile, script purposessmart-contracts/compiling - PlutusV1/V2/V3 compilationsmart-contracts/plutus-data - FromData/ToData derivationtesting/debugging - Debugging techniquesOptimization (for production contracts):
smart-contract-optimisations - overview: script size and execution unitssmart-contract-optimisations/measuring-performance - measure before optimizingoptimize-contract skill for a full optimization review.Language features:
language-guide/data-types - Scalus data typeslanguage-guide/builtin-functions - Built-in functionsStudy existing validators before creating new ones:
https://scalus.org/llms-examples.txt - 21 complete validators with tests; HTLC is the reference style.scalus-examples/jvm/src/main/scala/scalus/examples/.Imports: an on-chain file needs two imports (Scalus 1.5.0 or newer).
import scalus.cardano.onchain.plutus.v3.* // ledger types, OutputDatum, ByteString, Data, FromData, ToData, @Compile
import scalus.cardano.onchain.plutus.prelude.* // List, Option, require, fail, log
import scalus.uplc.builtin.Data.toData and import scalus.uplc.builtin.ByteString.{hex, utf8}
only when the file uses them. They are methods, so v3 cannot re-export them.v1/v2 types next to v3.*; v3 re-exports the ones it uses.
Import members through v3 too: import scalus.cardano.onchain.plutus.v3.Value.*.
v1.TxId, v1.TxOutRef and v1.TxInfo are different types from the v3 ones.
Exception: a file that also imports scalus.cardano.ledger.* keeps explicit imports such as
scalus.cardano.onchain.plutus.v3.{Credential, Value}. Both wildcards define Value,
Credential, PolicyId and more, and the explicit import resolves the ambiguity.prelude.* in off-chain files: its List(...) and Option(...) replace Scala's.OutputDatum, ByteString, Data, FromData,
ToData or Compile from v3. There, import them from scalus.cardano.onchain.plutus.v2,
scalus.uplc.builtin and scalus.compiler.Annotations:
@Compile - marks code for Plutus compilation@Ignore - excludes from compilation (off-chain helpers only)inline - keyword for on-chain optimizationData structures:
derives FromData, ToData for case classesEq to derives and compare enums and case classes with ===.
a.toData == b.toData compiles to the same UPLC (measured); do not write it.Validation:
require(condition, message) - assertion with error messagefail(message) - explicit failuregetOrFail(option, message) - safe Option extractionSpec.expects(c), Spec.ensures(c) and .ensuring(r => c) (Scalus 1.4.0 or newer) are
specifications for scalus-verification, not checks: the compiler removes them, so the script
never runs them. Use require for every condition the script must enforce.Safe API (one rule per check; full table with rationale and costs:
https://scalus.org/docs/security/safe-api-cheatsheet). Check the project's Scalus version first:
everything below except hasOnly, inlineOrFail and getOrFail needs Scalus 1.2.0 or
newer; on 1.1.1 or older, write the expansion the cheatsheet lists in its "Replaces" column.
tx.mint.hasOnly(policyId, tokenName, signedQty) is the mint check (1 mints, -1 burns;
exactly that token under the policy, nothing else). Not quantityOf(...) === BigInt(1) alone.out.hasInlineDatum(expected). Use out.datum.inlineOrFail[T](msg) only to
read fields; inlineOrFail[T](msg) === expected costs 461 lovelace against 286 (measured).tx.findContinuingOutputOrFail(ownInput, msg) compares the whole address.
Never a credential-only finder (findOutputsByCredential, findOutputsByScriptHash): the
staking part can be swapped and the rewards redirected.tx.validFromOrFail(msg) (inclusive) and tx.validToOrFail(msg) (exclusive).
Never getValidityStartTime (removed in 1.4.0): it returns 0 on an unbounded range and every
deadline passes.list.singleOrFail(msg) for a size-one list, list.findUniqueOrFail(p, msg) for
exactly one match. Never .head after filter, never filter(p).length === BigInt(1).tx.inputs.findUniqueOrFail(_.resolved.address.credential === ownCred, msg).
It returns the input and is cheaper than inputs.count(p) === BigInt(1) (measured).tx.valuePaidTo(addr) / tx.valueSpentFrom(addr) (whole address, whole Value;
add .getLovelace for ADA). Never getAdaFromOutputs / getAdaFromInputs.value.getLovelace (one lookupCoin builtin at PV11). Never lovelaceAmount
(deprecated: a Data map walk, about 30 more machine steps per call). Reading the amount is
fine; comparing only the ADA of a script UTxO is not (V027 in the security review).value.hasNft(policyId, tokenName) (quantity exactly 1). Continuing value:
out.value.hasSameTokensAndAtLeastAda(ownInput.resolved.value), not === and not >=: a new
datum can need more min-ADA, and === then rejects the honest transaction that adds it. A
datum field that records the lovelace equals the new getLovelace, not the old amount.out.value.hasNft(policyId, name), out.datum.inlineOrFail[State](msg) and
the state's own rules); every continuing spend keeps it (hasNft on the continuing output); a
Burn redeemer branch allows only burning (onlyBurnsUnder), never true.tx.onlyBurnsUnder(policyId) (non-empty and every quantity negative).
tokens(policy).forall(_._2 < 0) is vacuously true on an empty map.address.credential.scriptHashOrFail(msg) / pubKeyHashOrFail(msg), never a
match with a fail fallback.a divCeil b for what the user owes, a divFloor b for what the contract pays out.
State the rounding direction; bare / hides it.=== and generic positions: === BigInt(1) (see "BigInt literals" below).BigInt literals:
BigInt; the implicit
Int => BigInt conversion applies and reads better:
BigInt-typed parameters: tx.mint.hasOnly(policyId, tokenName, 1),
Value.lovelace(2_000_000), outputs.at(0)val fee: BigInt = 1_000_000BigInt (member operators): qty < 5, qty >= 0BigInt(n) where inference fails without it:
=== / !== comparisons: qty === BigInt(1) - a plain literal does NOT compile here
(the extension infers Eq[BigInt | Int], which does not exist)Int (unsupported on-chain): Option.Some(BigInt(1)),
foldLeft(BigInt(0))(...), List(BigInt(1), BigInt(2))Intrinsics (prefer them): the compiler replaces these prelude calls with builtins or a direct
recursion. A hand-written Data walk or a non-intrinsic method that does the same job costs more.
Value, at PV11 with Options.valueBuiltins (both defaults): quantityOf and getLovelace
(lookupCoin), + (unionValue), -, * and unary - (scaleValue), containsAtLeast
(valueContains), insertCoin and withoutLovelace (insertCoin). Built on them:
hasNft, hasSameTokensAndAtLeastAda. Not intrinsic: lovelaceAmount (deprecated),
Value.apply, Value.lovelace, tokens, flatten, policyIds, isPositive.List backed by Data (every ScriptContext list: inputs, outputs, signatories, ...):
isEmpty, head, tail, contains, indexOf, deleteFirst, distinct, diff, and at PV11
drop and at (dropList). Not intrinsic: exists, filter, length, map. Write
xs.contains(x), not xs.exists(_ === x); xs.count(p), not xs.filter(p).length.PairList: isEmpty, head, tail, and drop at PV11. SortedMap / AssocMap:
singleton, empty.optimize-contract skill has the measured costs.Script purposes (Plutus V3):
spend - spending UTxOsmint - minting/burning tokensreward - withdrawing staking rewardscertify - stake certificatesvote - governance votingpropose - governance proposalsCompilation:
private given Options = Options.release
val compiled = PlutusV3.compile(MyValidator.validate)
Parameterized validators:
Data (compiled.program $ param.toData: per-instance
parameters built off-chain, blueprint application, scripts that must match an Aiken
blueprint), extend DataParameterizedValidator and decode it in the handler:
val p = param.to[MyParams].ParameterizedValidator[A] compiles A to its lowered form, not to Data. Applying
param.toData to it fails at run time with HeadList / DropList errors.shared/src/main/scala/.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub scalus3/scalus --plugin scalus7 skills in this plugin
/contract-testGuide for testing Scalus smart contracts. Use when writing unit, property, budget, or Emulator tests for Cardano validators./local-developmentUse when developing or testing Scalus smart contracts with the local Emulator and TxBuilder. Covers how to create an Emulator provider, submit transactions, test negative validator cases, and test confirmation delay and rollbacks./optimize-contractOptimize Scalus/Cardano smart contracts for execution budget (CPU steps and memory). Analyzes @Compile annotated validators for performance issues — expensive patterns, unnecessary allocations, redundant traversals, missed short-circuits. Provides concrete Scalus rewrites with budget impact estimates. Use when reviewing on-chain code performance or when /optimize-contract is invoked. Requires explicit path argument.Other plugins' skills for the same job