Spending from Script
Unlock funds from a script address using redeemers
Spending from Script
Spending from a script means consuming a UTxO locked at a script address by providing a redeemer — the data your validator checks to authorize the spend. Evolution SDK handles script evaluation, redeemer indexing, and collateral selection automatically.
Basic Spend
Use collectFrom to specify which script UTxOs to spend and what redeemer to provide:
import {
,
,
,
,
type ,
,
} from "@evolution-sdk/evolution"
const = .()
.({
: "https://cardano-preprod.blockfrost.io/api/v0",
: ..!
})
.({ : ..!, : 0 })
declare const : .[] // from client.getUtxos(scriptAddress)
declare const : any // compiled Plutus script (from Aiken build or Blueprint codegen)
// Spend script UTxOs with a "Claim" redeemer
const = await
.()
.({
: ,
: .(0n, []) // Constructor 0 = Claim
})
.({ : })
.()
const = await .()
const = await .()With Required Signer
Many validators check that a specific key signed the transaction. Use addSigner to include the required signer:
import {
,
,
,
,
,
type ,
,
} from "@evolution-sdk/evolution"
const = .()
.({
: "https://cardano-preprod.blockfrost.io/api/v0",
: ..!
})
.({ : ..!, : 0 })
declare const : .[] // from client.getUtxos(scriptAddress)
declare const : any // compiled Plutus script (from Aiken build or Blueprint codegen)
declare const : .
const = await
.()
.({
: ,
: .(0n, []) // Claim action
})
.({ : })
.({ : })
.()
const = await .()
await .()With Time Constraints
For time-locked validators, set the transaction validity interval so the script can verify the current time:
import {
,
,
type ,
,
} from "@evolution-sdk/evolution"
const = .()
.({
: "https://cardano-preprod.blockfrost.io/api/v0",
: ..!
})
.({ : ..!, : 0 })
declare const : .[] // from client.getUtxos(scriptAddress)
declare const : any // compiled Plutus script (from Aiken build or Blueprint codegen)
const = (.())
const = await
.()
.({
: ,
: .(0n, [])
})
.({ : })
.({
: , // Valid from now
: + 300_000n // Expires in 5 minutes
})
.()
const = await .()
await .()Spend and Pay in One Transaction
Collect from a script and send the unlocked funds to a recipient:
import {
,
,
,
,
type ,
,
} from "@evolution-sdk/evolution"
const = .()
.({
: "https://cardano-preprod.blockfrost.io/api/v0",
: ..!
})
.({ : ..!, : 0 })
declare const : .[] // from client.getUtxos(scriptAddress)
declare const : any // compiled Plutus script (from Aiken build or Blueprint codegen)
const = .("addr_test1vrm9x2dgvdau8vckj4duc89m638t8djmluqw5pdrFollw8qd9k63")
const = await
.()
.({
: ,
: .(0n, [])
})
.({ : })
.({
: ,
: .(10_000_000n)
})
.()
const = await .()
await .()Redeemer Modes
The redeemer parameter supports three modes for different complexity levels. See the Redeemers page for details.
Static — Direct data value (most common):
redeemer: Data.constr(0n, [])Self — Callback that receives the input's final index:
redeemer: (input) => Data.constr(0n, [BigInt(input.index)])Batch — Callback for coordinating multiple inputs:
redeemer: {
all: (inputs) => Data.constr(0n, inputs.map(i => BigInt(i.index))),
inputs: [utxo1, utxo2]
}Debug Labels
Add labels to identify operations in error messages when debugging script failures:
import {
,
,
type ,
,
} from "@evolution-sdk/evolution"
const = .()
.({
: "https://cardano-preprod.blockfrost.io/api/v0",
: ..!
})
.({ : ..!, : 0 })
declare const : .[]
declare const : any
const = await
.()
.({
: ,
: .(0n, []),
: "claim-escrow" // Appears in error messages
})
.({ : })
.()Next Steps
- Redeemers — Deep dive on static, self, and batch modes
- Locking to Script — Lock funds before spending
- Reference Scripts — Reduce transaction size
- Time — Validity interval configuration