### Start Svelte Development Server Source: https://github.com/aiken-lang/aiken/blob/main/examples/gift_card/README.md Run this command to start a local development server for your Svelte project. The `--open` flag will automatically open the application in your default browser. ```bash npm run dev ``` ```bash npm run dev -- --open ``` -------------------------------- ### Install Aiken CLI Source: https://github.com/aiken-lang/aiken/blob/main/crates/aiken/README.md Install the Aiken command-line application using Cargo. This command bundles all other crates in the project. ```bash cargo install aiken ``` -------------------------------- ### Aiken Project Configuration with Dependencies Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/QUICKREF.md An example of an `aiken.toml` file including custom configuration and project dependencies. ```toml [config.default] max = 1000 [config.production] max = 10000 [[dependencies]] name = "aiken/stdlib" version = "^1.0.0" ``` -------------------------------- ### Initialize Mesh Project Source: https://github.com/aiken-lang/aiken/blob/main/examples/hello_world/README.md Sets up a new Node.js project and installs the necessary Mesh SDK and TypeScript runtime. This is required for frontend integration. ```bash npm init -y npm install @meshsdk/core tsx ``` -------------------------------- ### Build Aiken Project Source: https://github.com/aiken-lang/aiken/blob/main/examples/hello_world/README.md Compiles the Aiken smart contract project. Ensure you have Aiken installed and the project is set up correctly. ```bash aiken build ``` -------------------------------- ### Complete Aiken Project Configuration Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/configuration.md A comprehensive example of an `aiken.toml` file, demonstrating project metadata, dependencies, and environment-specific configurations for default, staging, and production. ```toml name = "my-nft-contract" version = "0.1.0" compiler = "1.1.22" license = "Apache-2.0" description = "NFT minting and management contract" plutus = "v3" [repository] url = "https://github.com/user/my-nft-contract" [[dependencies]] name = "aiken/stdlib" version = "^1.0.0" [[dependencies]] name = "user/utils" version = "^0.1.0" git = "https://github.com/user/utils" ref = "main" [config.default] max_supply = 10000 allow_burn = true royalty_percent = 10 creator_address = [0x01, 0x02, 0x03, 0x04] [config.staging] max_supply = 1000 allow_burn = false royalty_percent = 5 [config.production] max_supply = 10000 allow_burn = true royalty_percent = 10 creator_address = [0x01, 0x02, 0x03, 0x04] ``` -------------------------------- ### Data Constructor Calls in Aiken Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-expr.md Provides examples of calling data constructors, including those with and without arguments, and from different modules. ```aiken Some(x) None Pair(a, b) MyType(field1, field2) ``` -------------------------------- ### PlutusData Serialization to CBOR Example Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/uplc-library.md Demonstrates serializing PlutusData to canonical CBOR encoding using the `plutus_data_to_bytes` public function. Includes an example of encoding an integer. ```rust use uplc::{PlutusData, plutus_data_to_bytes}; let int_data = PlutusData::BigInt(42.into()); let bytes = plutus_data_to_bytes(&int_data); println!("Encoded: {:?}", hex::encode(&bytes)); ``` -------------------------------- ### Example: Generate and Print Validator UPLC Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-codegen.md Demonstrates how to compile a project, initialize a code generator, and then generate and print the UPLC for a specific validator. Handles potential generation errors. ```rust use aiken_lang::gen_uplc::CodeGenerator; use aiken_project::Project; let mut project = Project::new(root, listener)?; project.compile(options)?; let mut generator = project.new_generator(Tracing::silent()); match generator.generate_validator("my_module", "spend_validator") { Ok(program) => { let pretty = program.to_pretty(); println!("Generated UPLC:\n{}", pretty); } Err(e) => eprintln!("Generation error: {:?}", e), } ``` -------------------------------- ### Default Environment Configuration Module Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/configuration.md Example of the generated `env/default.ak` file, exposing default configuration constants for use in Aiken projects. ```aiken pub const max_supply: Int = 1000000 pub const allow_mint: Bool = true pub const fee_percent: Int = 2 ``` -------------------------------- ### Example: Integrate Aiken Project Compilation with Code Generation Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-codegen.md Shows the typical workflow of compiling an Aiken project and then using the `CodeGenerator` to generate UPLC for validators or modules. It highlights setting compilation options and iterating through project modules. ```rust use aiken_project::{Project, options::{Options, CodeGenMode}}; let mut project = Project::new(root, listener)?; // Compile first project.compile(Options { code_gen_mode: CodeGenMode::Build(false), ..Options::default() })?; // Then use generator let mut gen = project.new_generator(Tracing::silent()); // Generate specific validator let program = gen.generate_validator("module", "validator")?; // Or work with all modules for module in project.modules() { gen.generate_module(&module)?; } ``` -------------------------------- ### Program Struct Definition Example Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/uplc-library.md Illustrates the structure of a complete Plutus/UPLC program, including its version and root term. Shows how to convert it to a pretty-printed string. ```rust use uplc::ast::{Program, Name}; let program: Program = Program { version: Version::V3, term: /* ... */ }; let pretty = program.to_pretty(); println!("{}", pretty); ``` -------------------------------- ### Changelog Entry Format Source: https://github.com/aiken-lang/aiken/blob/main/CONTRIBUTING.md Example of how to format new entries in the CHANGELOG.md file for different types of changes (Added, Changed, Removed). ```markdown ## [next] - YYYY-MM-DD ### Added - **crate**: some new thing ### Changed - **crate**: fixed or updated something ### Removed - **crate**: something is gone now ``` -------------------------------- ### Aiken Project Configuration: Optional Fields Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/QUICKREF.md Details optional fields for `aiken.toml`, including their types, default values, and examples. ```markdown | Field | Type | Default | Example | |---|---|---|---| | plutus | string | v3 | `"v3"` | | license | string | — | `"Apache-2.0"` | | description | string | "" | `"My contract"` | | repository.url | string | — | `"https://..."` | ``` -------------------------------- ### PlutusData Serialization and Deserialization Example Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/uplc-library.md Demonstrates how to create, serialize to CBOR, and deserialize PlutusData using the `encode_fragment` and `decode_fragment` methods. ```rust use uplc::PlutusData; // Create an integer let int_data = PlutusData::BigInt(42.into()); // Create a list let list_data = PlutusData::Array( MaybeIndefArray::Def(vec![ PlutusData::BigInt(1.into()), PlutusData::BigInt(2.into()), ]) ); // Serialize let bytes = int_data.encode_fragment(); // Deserialize let decoded = PlutusData::decode_fragment(&bytes)?; ``` -------------------------------- ### Data Expressions Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/QUICKREF.md Examples of constructing data types and accessing fields in Aiken. ```aiken Some(x) // Constructor record.field // Access ``` -------------------------------- ### Aiken Project Configuration: Required Fields Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/QUICKREF.md Details the mandatory fields for the `aiken.toml` configuration file, including their types and examples. ```markdown | Field | Type | Example | |---|---|---| | name | string | `"my-project"` | | version | semver | `"0.1.0"` | | compiler | semver | `"1.1.22"` | ``` -------------------------------- ### Setup Blockfrost Project ID Source: https://github.com/aiken-lang/aiken/blob/main/examples/hello_world/README.md Exports the Blockfrost Project ID as an environment variable. This is necessary for interacting with the Cardano blockchain via Blockfrost. ```bash export BLOCKFROST_PROJECT_ID=preprod... ``` -------------------------------- ### SimpleExpr Variants Example Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-project-config.md Demonstrates the creation of different SimpleExpr variants: Integer, Boolean, Byte Array, and List. Useful for understanding how configuration values are represented. ```rust use aiken_project::config::SimpleExpr; let config_value = SimpleExpr::Int(42); let bool_value = SimpleExpr::Bool(true); let bytes = SimpleExpr::ByteArray(vec![0x00, 0x01], Default::default()); let list = SimpleExpr::List(vec![ SimpleExpr::Int(1), SimpleExpr::Int(2), ]); ``` -------------------------------- ### Constr Struct Definition and Examples Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/uplc-library.md Defines the Constr struct for constructor data with tag and fields. Provides examples for creating 'some' and 'none' variants. ```rust use uplc::Constr; // Create a Maybe variant let maybe_some = Constr { tag: 0, any_constructor: None, fields: vec![value].into(), }; let maybe_none = Constr { tag: 1, any_constructor: None, fields: vec![].into(), }; ``` -------------------------------- ### Pattern Matching Example Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-expr.md Demonstrates pattern matching on a transaction redeemer using a 'when' expression. Covers different patterns like constructors and wildcards. ```aiken when transaction.redeemer is { Spend(amount) -> amount > 0 Mint -> True _ -> False } ``` -------------------------------- ### Variable and Function References in Aiken Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-expr.md Provides examples of referencing variables, functions, or other identifiers in Aiken. ```aiken x add some_function ``` -------------------------------- ### Complete Function Example Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-expr.md A complete Aiken function definition demonstrating a pipeline operation for mapping over a list. Shows function signature and body implementation. ```aiken pub fn process(items: List) -> List { items |> list.map(fn(x) { x + 1 }) } ``` -------------------------------- ### Control Flow Expressions Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/QUICKREF.md Examples of conditional and pattern matching expressions in Aiken. ```aiken if condition { a } else { b } // Conditional when x is { Some(v) -> v; None -> 0 } // Pattern match ``` -------------------------------- ### Get All Built-in Functions Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-builtins.md Fetches all available built-in functions along with their type signatures. This requires module type information to be set up. ```rust let mut module_types = HashMap::new(); module_types.insert(builtins::PRELUDE.to_string(), prelude_types); let functions = builtins::prelude_functions(&id_gen, &module_types); ``` -------------------------------- ### Get Importable Modules Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-project-main.md Retrieves a list of all modules that can be imported within the Aiken project, including built-in modules. Use this to understand the available modules for your project. ```rust pub fn importable_modules(&self) -> Vec ``` -------------------------------- ### Project::new Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-project-main.md Creates a new Aiken project instance by loading configuration from the specified root directory. It requires a path to the project's root and an event listener for build notifications. ```APIDOC ## Project::new ### Description Creates a new project instance by loading configuration from the root directory. ### Method `pub fn new(root: PathBuf, event_listener: T) -> Result, Error>` ### Parameters #### Path Parameters - **root** (PathBuf) - Required - Path to the project root directory containing aiken.toml - **event_listener** (T) - Required - Event listener for build notifications ### Response #### Success Response - `Project` - On success, a new Project instance. #### Error Response - `Error` - If aiken.toml is missing or has invalid configuration ### Example ```rust use aiken_project::Project; use std::path::PathBuf; struct MyEventListener; impl aiken_project::telemetry::EventListener for MyEventListener { fn handle_event(&self, event: aiken_project::telemetry::Event) { println!("Event: {:?}", event); } } let root = PathBuf::from("./my_project"); match Project::new(root, MyEventListener) { Ok(project) => println!("Project loaded"), Err(e) => eprintln!("Error: {:?}", e), } ``` ``` -------------------------------- ### Clone and Test Aiken Project Source: https://github.com/aiken-lang/aiken/blob/main/CONTRIBUTING.md Steps to clone the Aiken repository, navigate into the directory, and run initial tests and the help command. ```bash git clone git@github.com:aiken-lang/aiken.git cd aiken cargo test cargo run -- help ``` -------------------------------- ### Get hex dump of message Source: https://github.com/aiken-lang/aiken/blob/main/crates/uplc/test_data/conformance/v3/builtin/semantics/verifyEcdsaSecp256k1Signature/README.md Converts the message file into a hex-encoded string. ```bash xxd -p msg.txt ``` -------------------------------- ### Project::new_with_config Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-project-main.md Creates a new Aiken project with a provided configuration, bypassing the need to load from disk. This method takes the project configuration, root directory path, and an event listener. ```APIDOC ## Project::new_with_config ### Description Creates a new project with a provided configuration instead of loading from disk. ### Method `pub fn new_with_config(config: ProjectConfig, root: PathBuf, event_listener: T) -> Project` ### Parameters #### Path Parameters - **config** (ProjectConfig) - Required - Parsed project configuration - **root** (PathBuf) - Required - Root directory path - **event_listener** (T) - Required - Event listener for notifications ### Response #### Success Response - `Project` - A new project instance with the provided configuration ### Example ```rust // Example usage would require defining ProjectConfig and a concrete type for T // let config = ProjectConfig { ... }; // let root = PathBuf::from("./my_project"); // let project = Project::new_with_config(config, root, MyEventListener); ``` ``` -------------------------------- ### PlutusData Deserialization from CBOR Example Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/uplc-library.md Shows how to deserialize PlutusData from CBOR-encoded bytes using the `plutus_data` public function. ```rust use uplc::plutus_data; let cbor_bytes = vec![0x18, 0x2a]; // CBOR encoding of 42 let data = plutus_data(&cbor_bytes)?; println!("{:?}", data); ``` -------------------------------- ### Create a New Svelte Project Source: https://github.com/aiken-lang/aiken/blob/main/examples/gift_card/README.md Use these commands to initialize a new Svelte project. The first command creates a project in the current directory, while the second creates it in a specified directory. ```bash npx sv create ``` ```bash npx sv create my-app ``` -------------------------------- ### Basic TOML Project Configuration Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-project-config.md Illustrates the fundamental structure of an aiken.toml file, including project metadata, repository information, and dependencies. ```toml name = "my_project" version = "0.1.0" compiler = "1.1.22" license = "Apache-2.0" description = "My Aiken project" [repository] url = "https://github.com/user/my_project" [[dependencies]] name = "aiken/stdlib" version = ">=1.0.0" ``` -------------------------------- ### Accessing Environment Configuration in Aiken Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/configuration.md Demonstrates how environment configuration constants are exposed in Aiken code and how to use them within validators. ```aiken // config/default.ak pub const max_supply: Int = 1000000 pub const allow_mint: Bool = true pub const fee_percent: Int = 2 ``` ```aiken import config validator spend(redeemer: Redeemer) { let total_minted = redeemer.amount total_minted <= config.max_supply && config.allow_mint } ``` -------------------------------- ### Initialize Aiken Project Options Source: https://github.com/aiken-lang/aiken/blob/main/crates/aiken-project/templates/_layout.html This JavaScript code initializes project-specific options like theme and prewrap settings. It reads preferences from local storage or uses default values, applies them as body classes, and updates the UI accordingly. ```javascript "use strict"; window.breadcrumbs = '{{ breadcrumbs }}'; const aikenConfig = { theme: { values: (() => { const dark = { value: "dark", label: "Switch to light mode", icons: ["moon"], }; const light = { value: "light", label: "Switch to dark mode", icons: ["sun"], }; return ( window.matchMedia("(prefers-color-scheme: dark)").matches ? [dark, light] : [light, dark] ).map((item, index) => { item.icons.push(`toggle-${0 === index ? "left" : "right"}`); return item; }); })(), update: () => "light" === Aiken.getProperty("theme") ? "dark" : "light", callback: function(value) { const syntaxThemes = { dark: "atom-one-dark", light: "atom-one-light", }; const syntaxTheme = document.querySelector("#syntax-theme"); const hrefParts = syntaxTheme.href.match( /^(.*?)([^/\\#?]+?)((?:\.min)?\.css.*)$/i ); if (syntaxThemes[value] !== hrefParts[2]) { hrefParts[2] = syntaxThemes[value]; hrefParts.shift(); syntaxTheme.href = hrefParts.join(""); } }, }, prewrap: { values: [ { value: "off", label: "Switch to line-wrapped snippets", icons: ["more-horizontal", "toggle-left"], }, { value: "on", label: "Switch to non-wrapped snippets", icons: ["more-vertical", "toggle-right"], }, ], update: () => "off" === Aiken.getProperty("prewrap") ? "on" : "off", }, }; "use strict"; /* Initialise options before any content loads */ void function() { for (const property in aikenConfig) { const name = `Aiken.${property}`; let value; try { value = localStorage.getItem(name); if (value.startsWith('"') && value.endsWith('"')) { localStorage.setItem(name, value.slice(1, value.length - 1)); } } catch (_error) {} const defaultValue = aikenConfig[property].values[0].value; try { value = localStorage.getItem(name); } catch(_error) {} if (-1 < [null, undefined].indexOf(value)) { value = defaultValue; } const bodyClasses = document.body.classList; bodyClasses.remove(`${property}-${defaultValue}`); bodyClasses.add(`${property}-${value}`); try { aikenConfig[property].callback(value); } catch(_error) {} } }(); ``` -------------------------------- ### Byte Array Operations Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-builtins.md Utilities for working with byte arrays, including concatenation, taking/dropping bytes, getting length, and slicing. ```APIDOC ## Byte Array Operations ### Description Functions for byte array manipulation. ### Functions - **append**: `(ByteArray, ByteArray) -> ByteArray` - Concatenate byte arrays - **take**: `(ByteArray, Int) -> ByteArray` - Take first n bytes - **drop**: `(ByteArray, Int) -> ByteArray` - Drop first n bytes - **length**: `(ByteArray) -> Int` - Get byte count - **slice**: `(ByteArray, Int, Int) -> ByteArray` - Extract substring ``` -------------------------------- ### Function Calls in Aiken Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-expr.md Demonstrates how to call functions with arguments, including standard calls and method-like calls on lists. ```aiken add(x, y) list.map(items, transform) my_func(a, b, c) ``` -------------------------------- ### Aiken Import Style Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-format.md Demonstrates the correct formatting for importing modules and specific functions in Aiken. ```aiken use aiken/list use aiken/string.{concat, length} ``` -------------------------------- ### Get Prelude Type Info Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-builtins.md Retrieves type information for the Aiken prelude. This is a foundational step before accessing other built-in functions or types. ```rust use aiken_lang::{IdGenerator, builtins}; use std::collections::HashMap; let id_gen = IdGenerator::new(); // Get prelude type info let prelude_types = builtins::prelude(&id_gen); ``` -------------------------------- ### Create New Aiken Project Instance Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-project-main.md Instantiates a new Aiken project by loading configuration from the specified root directory. Requires a custom event listener to handle build notifications. ```rust use aiken_project::Project; use std::path::PathBuf; struct MyEventListener; impl aiken_project::telemetry::EventListener for MyEventListener { fn handle_event(&self, event: aiken_project::telemetry::Event) { println!("Event: {:?}", event); } } let root = PathBuf::from("./my_project"); match Project::new(root, MyEventListener) { Ok(project) => println!("Project loaded"), Err(e) => eprintln!("Error: {:?}", e), } ``` -------------------------------- ### Parse Source Code Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/QUICKREF.md Parses source code into an untyped module. Use this to get an initial representation of your code before type checking. ```rust use aiken_lang::{parser, ast::ModuleKind}; let (untyped_module, extra) = parser::module(source, ModuleKind::Lib)?; // Result: UntypedModule with no type information ``` -------------------------------- ### Create Aiken Project with Provided Configuration Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-project-main.md Creates a new Aiken project instance using a pre-existing configuration object, root directory, and an event listener. ```rust pub fn new_with_config( config: ProjectConfig, root: PathBuf, event_listener: T ) -> Project ``` -------------------------------- ### prelude Initialization Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-builtins.md Initializes type information for all prelude types and functions. ```APIDOC ## prelude ### Description Returns type information for all prelude types and functions. ### Signature `pub fn prelude(id_gen: &IdGenerator) -> TypeInfo` ### Parameters - **id_gen** (`&IdGenerator`): Generator for unique type variable IDs ### Return Type `TypeInfo` — Complete type information for all built-in definitions ``` -------------------------------- ### Create and Serialize Blueprint Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-project-blueprint.md Creates a blueprint from project configuration and modules, then serializes it to a JSON file. Ensure the project is compiled before generating the blueprint. ```rust use aiken_project::{Project, blueprint::Blueprint, options::BlueprintExport}; use std::path::PathBuf; // After compiling your project let mut project = Project::new(PathBuf::from("."), listener)?; project.compile(compile_options)?; // Generate blueprint let blueprint_path = PathBuf::from("build/tmp.json"); let blueprint = Blueprint::new( &project.config, &project.checked_modules, &mut generator, true // export all types ).map_err(|e| aiken_project::Error::Blueprint(e.into()))?; // Serialize to JSON let json = serde_json::to_string_pretty(&blueprint)?; std::fs::write(&blueprint_path, json)?; ``` -------------------------------- ### Build Svelte Project for Production Source: https://github.com/aiken-lang/aiken/blob/main/examples/gift_card/README.md Execute this command to generate an optimized production build of your Svelte application. ```bash npm run build ``` -------------------------------- ### Example Aiken Validator Source: https://github.com/aiken-lang/aiken/blob/main/examples/monorepo/README.md A basic validator function named 'always_true' that always returns True. Place validator files in the 'validators' folder with a .ak extension. ```aiken validator { fn spend(_datum: Data, _redeemer: Data, _context: Data) -> Bool { True } } ``` -------------------------------- ### Load Aiken Project Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/QUICKREF.md Initializes a new Aiken project instance by providing the project root directory and a listener for build events. ```rust Project::new(root, listener)? ``` -------------------------------- ### Project Description Configuration Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/configuration.md Provides a short description of the project. This field is optional and defaults to an empty string. ```toml description = "A contract for managing NFTs on Cardano" ``` -------------------------------- ### Get Built-in Data Types Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-builtins.md Retrieves definitions for all built-in data types. This function is essential for understanding and using Aiken's fundamental data structures. ```rust // Get built-in data types let data_types = builtins::prelude_data_types(&id_gen); ``` -------------------------------- ### Basic Aiken Test Source: https://github.com/aiken-lang/aiken/blob/main/examples/monorepo/README.md An example of a simple test case written within an Aiken module using the 'test' keyword. Tests verify the correctness of your Aiken code. ```aiken test foo() { 1 + 1 == 2 } ``` -------------------------------- ### Execute V3 Script Context Tests with Dev Build Source: https://github.com/aiken-lang/aiken/blob/main/examples/acceptance_tests/script_context/v3/README.md Run the test suite using a development build of the project. This is useful for faster iteration during testing. ```bash ./test.sh VALIDATOR_GROUP "cargo run --" ``` -------------------------------- ### Get Project Policy ID in Rust Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/QUICKREF.md Retrieve the policy ID for a project's validator using the 'project.policy' function in Rust. Requires the blueprint and validator name. ```rust let policy = project.policy( None, # module Some("mint"), # validator &blueprint )?; ``` -------------------------------- ### Aiken Configuration Environments Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-project-config.md Demonstrates how environment-specific configurations defined in aiken.toml are accessed in Aiken code, typically via constants in files like config/default.ak. ```aiken const max_supply = 1000000 const allow_mint = true ``` -------------------------------- ### Project::docs Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-project-main.md Generates HTML documentation for the Aiken project. This method allows specifying an output destination and whether to include documentation for dependency modules. ```APIDOC ## `Project::docs` ### Description Generates HTML documentation for the project. ### Method `docs` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **destination** (Option) - Optional - Output directory for generated documentation (defaults to './docs') - **include_dependencies** (bool) - Required - Whether to document dependency modules ### Request Example None provided in source. ### Response #### Success Response (200) Unit type on success. #### Response Example None (returns `Ok(())` on success) ### Throws - `Vec` — Compilation errors ``` -------------------------------- ### Get Aiken Compiler Version Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-project-config.md Retrieves the current Aiken compiler version. Use `short: true` for a concise version string, or `short: false` for the full version information. ```rust use aiken_project::config; let full_version = config::compiler_version(false); let short_version = config::compiler_version(true); println!("Compiler: {}", full_version); ``` -------------------------------- ### Program Serialization Methods Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-codegen.md Shows how to serialize a generated Aiken UPLC program into different formats: pretty-printed text, CBOR (for on-chain use), and Flat format. ```rust // To pretty-printed UPLC text let pretty = program.to_pretty(); ``` ```rust // To CBOR (on-chain format) let cbor_bytes = program.encode(); ``` ```rust // To Flat format let flat_bytes = program.to_flat(); ``` -------------------------------- ### TOML Configuration Environments Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-project-config.md Shows how to define environment-specific configurations within the aiken.toml file using tables like [config.default], [config.staging], and [config.production]. ```toml [config.default] max_supply = 1000000 allow_mint = true [config.staging] max_supply = 100000 allow_mint = false [config.production] max_supply = 1000000 allow_mint = true ``` -------------------------------- ### Create a new Aiken Formatter instance Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-format.md Creates a new formatter with the standard line width (typically 100 columns). ```rust use aiken_lang::format::Formatter; let formatter = Formatter::new(); ``` -------------------------------- ### Formatter::new Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-format.md Creates a new formatter with default settings, typically using a standard line width of 100 columns. ```APIDOC ## Formatter::new ### Description Creates a new formatter with the standard line width (typically 100 columns). ### Method ```rust pub fn new() -> Self ``` ### Return Type `Formatter` — New formatter instance ### Example ```rust use aiken_lang::format::Formatter; let formatter = Formatter::new(); ``` ``` -------------------------------- ### Project License Configuration Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/configuration.md Specifies the project's license identifier, preferably in SPDX format. This field is optional. ```toml license = "Apache-2.0" ``` ```toml license = "MIT" ``` ```toml license = "GPL-3.0" ``` -------------------------------- ### Compile and Build Aiken Project Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/QUICKREF.md Methods for compiling and building an Aiken project, with options for UPLC generation, tracing, and output paths. ```rust project.compile(options)? project.build(uplc, tracing, path, export, env)? ``` -------------------------------- ### Tuple Literals in Aiken Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-expr.md Shows how to create tuple literals, which are fixed-size heterogeneous collections. ```aiken (x, y) (1, "hello", True) ``` -------------------------------- ### Compile with Specific Environment Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/configuration.md Build your Aiken project for a particular environment using the `--env` flag during compilation. ```bash aiken build --env production ``` -------------------------------- ### Generate Aiken Project Documentation Source: https://github.com/aiken-lang/aiken/blob/main/examples/monorepo/README.md Command to generate HTML documentation for an Aiken library. This is useful for sharing your code and its usage. ```sh aiken docs ``` -------------------------------- ### Initialize CodeGenerator Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-codegen.md Creates a new `CodeGenerator` instance. This is the entry point for UPLC code generation. ```rust pub fn new_generator(&self, tracing: Tracing) -> CodeGenerator<'_> ``` -------------------------------- ### Minimal Aiken Project Configuration Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/QUICKREF.md The essential fields required in an `aiken.toml` file to define a new project. ```toml name = "my-project" version = "0.1.0" compiler = "1.1.22" ``` -------------------------------- ### Project Version Configuration Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/configuration.md Defines the semantic version of the project. Must follow the MAJOR.MINOR.PATCH format. ```toml version = "0.1.0" ``` -------------------------------- ### Project Name Configuration Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/configuration.md Specifies the project identifier, used as the package name. Must be lowercase alphanumeric with hyphens. ```toml name = "my-contract" ``` -------------------------------- ### List Literals in Aiken Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-expr.md Demonstrates the creation of empty lists, lists with elements, and lists with a tail. ```aiken [] [1, 2, 3] [x, ..rest] [head, ..tail] ``` -------------------------------- ### Aiken Project Directory Layout Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/configuration.md Illustrates the standard directory structure for an Aiken project, including configuration, libraries, validators, and environment files. ```text project/ ├── aiken.toml # Project configuration ├── lib/ # Library modules │ └── module_name.ak ├── validators/ # Validator definitions │ └── validator_name.ak ├── env/ # Environment configuration │ ├── default.ak # Required: default environment │ ├── staging.ak │ └── production.ak └── config/ # Generated configuration module (auto-created) ``` -------------------------------- ### Format Aiken definitions and convert to string Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-format.md Formats a list of definitions and returns self for chaining, then finalizes formatting with a specified line width. ```rust let formatted = formatter .definitions(&definitions) .to_pretty_string(100); ``` -------------------------------- ### Compile Project Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/QUICKREF.md Compiles an Aiken project, producing checked modules with full type information. Ensure the project root and a listener are provided. ```rust use aiken_project::Project; let mut project = Project::new(root, listener)?; project.compile(options)?; // Result: Checked modules with full type info ``` -------------------------------- ### Execute V3 Script Context Tests Source: https://github.com/aiken-lang/aiken/blob/main/examples/acceptance_tests/script_context/v3/README.md Run the test suite for a specific validator group. This command recompiles the project in release mode by default. ```bash ./test.sh VALIDATOR_GROUP ``` -------------------------------- ### Format a complete Aiken module Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-format.md Converts module AST back to properly formatted source code. Requires parsing the source into a module first. ```rust use aiken_lang::{parser, format::Formatter}; let source = r#"..."#; let (module, _) = parser::module(source, ModuleKind::Lib)?; let mut formatter = Formatter::new(); let formatted = formatter.format_module(&module); println!("{}", formatted); ``` -------------------------------- ### Repository URL Configuration Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/configuration.md Specifies the repository location for the project. This is an optional table. ```toml [repository] url = "https://github.com/user/my-contract" ``` -------------------------------- ### Byte Array Literals in Aiken Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-expr.md Illustrates the creation of byte array literals using hexadecimal notation or an array format. ```aiken let bytes = 0x00010203 let bytes = [0x00, 0x01, 0x02, 0x03] ``` -------------------------------- ### Sidebar Tooltip Integration Source: https://github.com/aiken-lang/aiken/blob/main/crates/aiken-project/templates/_layout.html This script initializes the 'tippy.js' library to add tooltips to sidebar navigation links, enhancing usability for truncated or indented items. ```javascript void function() { if (typeof tippy !== "undefined") { const overflowed = Array.from(document .querySelectorAll('.sidebar li:not(\[data-indent\])')) .filter(x => x.offsetWidth < x.scrollWidth); tippy(overflowed, { arrow: true, placement: 'right', content: (el) => el.children[0]?.innerText, }); tippy('.sidebar li[data-indent] a', { arrow: true, placement: 'right', content: (el) => el .getAttribute('href') .replaceAll(/\.?\.\ ecursive//g, '') .replace('.html', ''), }); } }(); ``` -------------------------------- ### Iterate Through Functions Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-builtins.md Demonstrates how to iterate through the retrieved built-in functions and print their names and return types. Useful for introspection and debugging. ```rust // Iterate through functions for (key, func) in functions.iter() { println!("{}: {:?}", key.name, func.return_type); } ``` -------------------------------- ### Compile Aiken Project Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/README.md Compiles an Aiken project using the `aiken_project` crate. Requires a project path and compilation options. ```rust use aiken_project::Project; use std::path::PathBuf; let mut project = Project::new(PathBuf::from("."), listener)?; project.compile(compile_options)?; ``` -------------------------------- ### Generate compressed verification key Source: https://github.com/aiken-lang/aiken/blob/main/crates/uplc/test_data/conformance/v3/builtin/semantics/verifyEcdsaSecp256k1Signature/README.md Generates a compressed verification key (public key) from the private key and stores it in DER format. ```bash openssl ec -in pk.der -outform DER -pubout -conv_form compressed -out vk.der ``` -------------------------------- ### Project::build Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-project-main.md A convenience method to build the project specifically for generating a blueprint (contract definition). It allows configuration of UPLC output, tracing, blueprint path, and export types. ```APIDOC ## `Project::build` ### Description Convenience method for building the project to generate a blueprint (contract definition). ### Method `build` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **uplc** (bool) - Required - Whether to also dump UPLC artifact files - **tracing** (Tracing) - Required - Tracing configuration for debugging - **blueprint_path** (PathBuf) - Required - Output path for the blueprint JSON file - **blueprint_export** (BlueprintExport) - Required - Which types to export (OnlyBinaryInterface or AllTypes) - **env** (Option) - Optional - Configuration environment to use ### Request Example None provided in source. ### Response #### Success Response (200) Unit type on success. #### Response Example None (returns `Ok(())` on success) ### Throws - `Vec` — Compilation errors ``` -------------------------------- ### Query Aiken Project Information Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/QUICKREF.md Retrieves various pieces of information about the project, such as modules, importable modules, glossary terms, and warnings. ```rust project.modules() -> Vec project.importable_modules() -> Vec project.glossary() -> &Glossary project.warnings() -> Vec ``` -------------------------------- ### Aiken Pattern Matching: Constructor Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/QUICKREF.md Use 'when' expressions for pattern matching on data constructors like Option's Some and None. ```aiken when value is { Some(x) -> x None -> 0 } ``` -------------------------------- ### Run CI Commands Locally Source: https://github.com/aiken-lang/aiken/blob/main/CONTRIBUTING.md Commands to run locally to ensure code quality and formatting checks before pushing changes. These mirror the CI pipeline. ```bash cargo build --workspace cargo test --workspace cargo fmt --all -- --check cargo clippy --all-targets --all-features -- -D warnings ``` -------------------------------- ### Format Aiken Code Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/QUICKREF.md Use the 'aiken fmt' command to format Aiken code. It can format all files in the project or specific files matching a pattern. ```bash aiken fmt # Format all aiken fmt path/*.ak # Format specific files ``` -------------------------------- ### Dependency Configuration Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/configuration.md Specifies external package dependencies, including name, version, and optional Git or local path sources. ```toml [[dependencies]] name = "aiken/stdlib" version = ">=1.0.0" ``` ```toml [[dependencies]] name = "aiken/list" version = "^1.0" ``` ```toml # Git source [[dependencies]] name = "my-org/my-lib" git = "https://github.com/my-org/my-lib" ref = "main" ``` ```toml # Local path [[dependencies]] name = "local/lib" path = "../my-lib" ``` -------------------------------- ### Formatter::to_pretty_string Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-format.md Finalizes the formatting process and returns the complete formatted output as a string, applying a specified line width. ```APIDOC ## Formatter::to_pretty_string ### Description Finalizes formatting with specified line width. ### Method ```rust pub fn to_pretty_string(self, width: usize) -> String ``` ### Parameters - **width** (`usize`) - Target line width (typically 100) ### Return Type `String` — Complete formatted output ### Example ```rust let formatted = formatter .definitions(&definitions) .to_pretty_string(100); ``` ``` -------------------------------- ### `Program` Methods Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/uplc-library.md Provides methods for pretty-printing UPLC programs and converting them to a specific type. ```APIDOC ## `Program` Methods ### `to_pretty` - **Description**: Pretty-print the UPLC program to a readable string. - **Method**: N/A (Method on `Program` struct) - **Parameters**: None - **Return Type**: `String` ### `try_into` - **Description**: Convert the program's term type. - **Method**: N/A (Method on `Program` struct) - **Parameters**: None - **Return Type**: `Result, Error>` ``` -------------------------------- ### Anonymous Functions (Lambdas) in Aiken Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-expr.md Shows the syntax for defining anonymous functions with parameters and a body. ```aiken fn(x) { x + 1 } fn(x, y) { x + y } ``` -------------------------------- ### Plutus Version Configuration Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/configuration.md Defines the target Plutus language version. Defaults to `v3`. ```toml plutus = "v3" ``` -------------------------------- ### Aiken Pattern Matching Style Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-format.md Shows the standard syntax for pattern matching with `when` expressions in Aiken. ```aiken when value is { Some(x) -> x + 1 None -> 0 } ``` -------------------------------- ### Aiken Project Dependencies Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/QUICKREF.md Define project dependencies in the toml format, specifying package name, version, and optionally git or local path sources. ```toml [[dependencies]] name = "owner/package" version = "^1.0.0" # or >=1.0.0, =1.0.0, etc. # Optional: # git = "https://..." # Instead of registry # path = "../local" # Local path # ref = "main" # Git branch/tag ``` -------------------------------- ### prelude_functions Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-builtins.md Retrieves all built-in functions along with their type signatures. This function is essential for understanding the available operations within the Aiken prelude. ```APIDOC ## prelude_functions ### Description Returns all built-in functions with their type signatures. This function is essential for understanding the available operations within the Aiken prelude. ### Signature `pub fn prelude_functions(id_gen: &IdGenerator, module_types: &HashMap) -> IndexMap` ### Parameters #### Path Parameters - **id_gen** (`&IdGenerator`) - Description: ID generator - **module_types** (`&HashMap`) - Description: Module type information ### Return Type `IndexMap` — All available functions ``` -------------------------------- ### Project::check Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-project-main.md Compiles the project and executes all defined tests. It offers options to skip tests, filter tests by pattern, control verbosity, and configure test execution parameters like seed and coverage. ```APIDOC ## `Project::check` ### Description Compiles the project and runs all tests. ### Method `check` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **skip_tests** (bool) - Required - If true, only compile without running tests - **match_tests** (Option>) - Optional - Filter tests by module and/or name patterns - **verbose** (bool) - Required - Enable verbose test output - **exact_match** (bool) - Required - Require exact test name matches (vs. substring) - **seed** (u32) - Required - Random seed for property-based tests - **property_max_success** (usize) - Required - Max iterations for property tests - **coverage_mode** (CoverageMode) - Required - Code coverage tracking mode - **tracing** (Tracing) - Required - Tracing configuration - **plain_numbers** (bool) - Required - Disable colored output for numbers - **env** (Option) - Optional - Configuration environment ### Request Example None provided in source. ### Response #### Success Response (200) Unit type on success. #### Response Example None (returns `Ok(())` on success) ### Throws - `Vec` — Compilation errors ``` -------------------------------- ### Pattern Matching with 'When' in Aiken Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-expr.md Illustrates the 'when' expression for pattern matching against a value, including guards. ```aiken when value is { Some(x) -> x + 1 None -> 0 x if x > 0 -> positive _ -> other } ``` -------------------------------- ### Formatter::format_module Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-format.md Formats a complete Aiken module by converting its Abstract Syntax Tree (AST) back into properly formatted source code. ```APIDOC ## Formatter::format_module ### Description Converts module AST back to properly formatted source code. ### Method ```rust pub fn format_module(&mut self, module: &Module) -> String ``` ### Parameters - **module** (`&Module`) - Module to format ### Return Type `String` — Formatted source code ### Example ```rust use aiken_lang::{parser, format::Formatter}; let (module, _) = parser::module(source, ModuleKind::Lib)?; let mut formatter = Formatter::new(); let formatted = formatter.format_module(&module); println!("{}", formatted); ``` ``` -------------------------------- ### Load Blueprint JSON Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-project-main.md Loads a blueprint JSON file from the specified path. This is useful for deserializing blueprint configurations. Ensure the file exists and is valid JSON. ```rust pub fn blueprint(path: &Path) -> Result ``` -------------------------------- ### Aiken Prelude Initialization Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-builtins.md Initialize type information for all built-in prelude types and functions using an ID generator. ```rust pub fn prelude(id_gen: &IdGenerator) -> TypeInfo ``` -------------------------------- ### Local Variable Binding with 'Let' in Aiken Source: https://github.com/aiken-lang/aiken/blob/main/_autodocs/api-reference/aiken-lang-expr.md Demonstrates the 'let' keyword for binding a value to a local variable within a scope. ```aiken let x = 42 let result = add(x, 10) result ```