Native Scripts
Comprehensive guide to Cardano Native scripts, their structure, components, and best practices when minting tokens with the Anvil API.
Introduction
What is a Native Script?
Native Script Structure
// Base structure for all native scripts
{
"type": "sig" | "before" | "after" | "all" | "any" | "atLeast",
// Additional properties based on the type
}// Main Native Script Schema
export const nativeScriptSchema = z.discriminatedUnion("type", [
// Signature requirement
z.object({ type: z.literal("sig"), keyHash: z.string() }),
// Time constraints
z.object({ type: z.enum(["before", "after"]), slot: z.number() }),
// Logical AND/OR
z.object({
type: z.enum(["any", "all"]),
scripts: z.array(/*recursive native scripts*/)
}),
// At least N of M
z.object({
type: z.literal("atLeast"),
required: z.number(),
scripts: z.array(/*recursive native scripts*/)
}),
]);Script Types
Common Native Script Patterns
Basic Single-Signature Policy
Time-Limited Single-Signature Policy (Recommended for NFTs)
Multi-Signature Policy (Any of Two Keys)
Multi-Signature Policy with Threshold (2 of 3 Keys Required)
Best Practices
Security Considerations
Implications for Token Operations
Using Native Scripts with the Anvil API
When to Include Native Scripts
Script Verification
Integration with Transaction Building
Common Errors and Troubleshooting
References
Last updated
Was this helpful?

