### SDK Not Installed Error Example Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/component-howtos/application-development/dpm-sandbox.rst Example of an error message indicating that the required Daml SDK version specified in 'daml.yaml' is not installed. ```none SDK not installed. Cannot run command without SDK. ``` -------------------------------- ### Install Daml SDK Source: https://github.com/digital-asset/daml/blob/main/sdk/compiler/daml-extension/README.md Use this command to install the Daml SDK. Ensure you have a working Daml SDK installed for full feature utilization. ```bash curl https://get.digitalasset.com/install/install.sh | sh ``` -------------------------------- ### Nested Project Structure Example Source: https://github.com/digital-asset/daml/blob/main/sdk/unreleased/multi-package.md Shows a setup with two separate repositories, 'application' and 'library', where the application depends on the library via DAR files. ```bash . .git ├── multi-package.yaml ├── application-logic │   └── daml.yaml └── application-tests    └── daml.yaml └── library-repository ├── .git ├── multi-package.yaml ├── library-logic │   └── daml.yaml └── library-tests    └── daml.yaml ``` -------------------------------- ### Install DADEW Environment Source: https://github.com/digital-asset/daml/blob/main/sdk/dev-env/windows/README.md Installs the local DADEW environment, which includes downloading and configuring the Scoop package manager. This is a one-time setup action. ```powershell .\dev-env\windows\bin\dadew.ps1 install ``` -------------------------------- ### Start nix-store-gcs-proxy Server Source: https://github.com/digital-asset/daml/blob/main/sdk/nix/tools/nix-store-gcs-proxy/README.md Start the proxy server by specifying the Google Cloud Storage bucket name. Ensure Google credentials are configured. ```sh ./nix-store-gcs-proxy --bucket-name ``` -------------------------------- ### Start Default Sandbox Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/component-howtos/application-development/dpm-sandbox.rst Run this command to start the Canton sandbox with its default configuration. It will output the listening port and readiness status. ```none $ dpm sandbox Starting Canton sandbox. Listening at port 6865 Canton sandbox is ready. ``` -------------------------------- ### Start Daml Sandbox Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/component-howtos/smart-contracts/assistant.rst Starts a Daml Sandbox, which is a reference ledger implementation. This command can also upload your current package. ```bash daml start ``` ```bash daml sandbox ``` -------------------------------- ### Install Local Daml SDK on Windows Source: https://github.com/digital-asset/daml/blob/main/sdk/README.md Steps to build the SDK release tarball, extract it, and install the local Daml SDK on Windows. Note that the Windows build is not yet fully functional. ```bash bazel build //release:sdk-release-tarball tar -vxf .\bazel-bin\release\sdk-release-tarball-ce.tar.gz cd sdk-* daml\daml.exe install . --install-assistant=yes ``` -------------------------------- ### Multi-package Configuration (multi-package.yaml) Example Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/component-howtos/smart-contracts/assistant/config-files.rst An example configuration file for managing multiple connected Daml packages, specifying directories for packages and other projects. ```yaml packages: - ./path/to/package/a - ./path/to/package/b projects: - ./path/to/project/a - ./path/to/project/b ``` -------------------------------- ### Example Project Structure Source: https://github.com/digital-asset/daml/blob/main/sdk/unreleased/multi-package.md Illustrates a project structure where a vendor library is included as a data dependency. ```bash > tree . ├── multi-package.yaml ├── package-Logic │   ├── daml ││   └── daml.yaml ├── package-Model │   ├── daml ││   ├── daml/.dist/package-Model-1.0.0.dar ││   └── daml.yaml └── vendor-library    ├── daml │   ├── daml/.dist/vendor-library-1.0.0.dar └── daml.yaml ``` -------------------------------- ### Install Daml SDK with custom directories Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/component-howtos/smart-contracts/assistant.rst When disk space is a concern, you can specify custom directories for DAML_HOME and TMPDIR before running the installer. This ensures sufficient space for the installation. ```sh DAML_HOME= TMPDIR= curl -sSL https://get.daml.com/ | sh ``` -------------------------------- ### Error Message for SDK Not Installed Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/sharable/sdk/component-howtos/application-development/dpm-sandbox.rst Example error message displayed when the 'daml.yaml' file specifies an SDK version that is not installed. ```none SDK not installed. Cannot run command without SDK. ``` -------------------------------- ### Install Nix on Linux Source: https://github.com/digital-asset/daml/blob/main/sdk/README.md Install the Nix package manager on Linux systems. This is a prerequisite for using the `dev-env` tool. ```bash bash <(curl -sSfL https://nixos.org/nix/install) ``` -------------------------------- ### Start Daml Sandbox Source: https://github.com/digital-asset/daml/blob/main/sdk/release/RELEASE.md Starts the Daml sandbox with a specified DAR file. Ensure you are in the project directory. ```sh dpm sandbox --dar ./.daml/dist/quickstart-0.0.1.dar ``` -------------------------------- ### List Installed SDK Versions Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/component-howtos/smart-contracts/assistant.rst Run 'daml version' to see all installed SDK versions, including the default and selected versions. It also indicates if an SDK specified in 'daml.yaml' is not installed. ```bash daml version ``` -------------------------------- ### Daml Example: FetchByKey and lookupByKey Scenarios Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/sharable/sdk/reference/daml/contract-keys.rst This Daml code snippet provides a comprehensive example demonstrating various success and failure scenarios for `fetchByKey` and `lookupByKey` operations, illustrating their behavior in different contexts. ```daml module Keys where import DA.Optional (Optional(..)) import DA.Time (Date) import Daml.Trigger (submit, register, unregister) import Daml.Script (getParty, script, assert, trace, traceShowId) -- Helper to create a contract with a key createContractWithKey :: forall r k. (HasCreate c k) => r -> k -> c -> Update (ContractId c) createContractWithKey owner key contract = do cid <- create contract return cid -- Helper to fetch a contract by key fetchByKey' :: (HasFetchByKey c k) => k -> Update (Optional (ContractId c, c)) fetchByKey' k = fetchByKey k -- Helper to lookup a contract by key lookupByKey' :: (HasFetchByKey c k) => k -> Update (Optional (ContractId c)) lookupByKey' k = lookupByKey k -- Helper to exercise a choice by key exerciseByKey' :: (HasExerciseByKey c choice k) => k -> choice -> Update (Set (ContractId c)) exerciseByKey' k choice = exerciseByKey k choice -- Example contract and key data MyContract = MyContract with owner: Party text: Text int: Int date: Date instance HasConsensus MyContract where getConsensus = undefined instance HasEvents MyContract where getEvents = undefined instance HasKey MyContract Party where getKey = Just . owner -- Example choice data MyChoice = IncrementInt | UpdateText Text instance HasExercise MyContract MyChoice where type ChoiceResult MyChoice = () -- No specific result for these choices exercise choice contractId choiceArg = case choice of IncrementInt -> do c <- fetch contractId let newInt = int c + 1 let newContract = c with int = newInt newCid <- create newContract return () UpdateText newText -> do c <- fetch contractId let newContract = c with text = newText newCid <- create newContract return () -- Example script -- This script demonstrates the usage of fetchByKey and lookupByKey. -- It covers scenarios like creating a contract, looking it up, fetching it, -- and handling cases where the contract does not exist. exampleScript :: Script () exampleScript = script do -- Get parties alice <- getParty "Alice" bob <- getParty "Bob" -- Define a contract key (Alice's party) let aliceKey = alice -- 1. Create a contract with a key let initialContract = MyContract with owner = alice; text = "initial"; int = 0; date = '2023-01-01' cid1 <- createContractWithKey alice aliceKey initialContract traceShowId ("Created contract with ID: " <> show cid1 <> " and key: " <> show aliceKey) -- 2. Lookup the contract by key (should exist) maybeCid2 <- lookupByKey' @MyContract aliceKey case maybeCid2 of Just cid2 -> do assert (cid1 == cid2) "Lookup returned wrong contract ID" traceShowId ("Successfully looked up contract with ID: " <> show cid2) Nothing -> assert False "Failed to lookup contract that should exist" -- 3. Fetch the contract by key (should exist) maybeContract3 <- fetchByKey' @MyContract aliceKey case maybeContract3 of Just (cid3, contract3) -> do assert (cid1 == cid3) "Fetch returned wrong contract ID" assert (initialContract == contract3) "Fetch returned wrong contract data" traceShowId ("Successfully fetched contract with ID: " <> show cid3 <> " and data: " <> show contract3) Nothing -> assert False "Failed to fetch contract that should exist" -- 4. Try to lookup a non-existent contract let nonExistentKey = bob maybeCid4 <- lookupByKey' @MyContract nonExistentKey case maybeCid4 of Just _ -> assert False "Lookup returned a contract for a non-existent key" Nothing -> traceShowId "Successfully confirmed non-existent contract for key: " <> show nonExistentKey -- 5. Try to fetch a non-existent contract maybeContract5 <- fetchByKey' @MyContract nonExistentKey case maybeContract5 of Just _ -> assert False "Fetch returned a contract for a non-existent key" Nothing -> traceShowId "Successfully confirmed non-existent contract fetch for key: " <> show nonExistentKey -- 6. Exercise a choice by key (IncrementInt) maybeCid6 <- lookupByKey' @MyContract aliceKey case maybeCid6 of Just cid6 -> do _ <- exerciseByKey' @MyContract aliceKey IncrementInt traceShowId "Successfully exercised IncrementInt choice by key" -- Verify the change by fetching again maybeContract6 <- fetchByKey' @MyContract aliceKey case maybeContract6 of Just (_, contract6) -> do assert (contract6.int == 1) "IncrementInt choice did not update the integer correctly" traceShowId "Verified contract integer incremented successfully" Nothing -> assert False "Contract disappeared after exercising choice" Nothing -> assert False "Failed to lookup contract for exercising choice" -- 7. Exercise a choice by key (UpdateText) maybeCid7 <- lookupByKey' @MyContract aliceKey case maybeCid7 of Just cid7 -> do let newText = "updated" _ <- exerciseByKey' @MyContract aliceKey (UpdateText newText) traceShowId "Successfully exercised UpdateText choice by key" -- Verify the change by fetching again maybeContract7 <- fetchByKey' @MyContract aliceKey case maybeContract7 of Just (_, contract7) -> do assert (contract7.text == newText) "UpdateText choice did not update the text correctly" traceShowId "Verified contract text updated successfully" Nothing -> assert False "Contract disappeared after exercising choice" Nothing -> assert False "Failed to lookup contract for exercising choice" -- 8. Demonstrate visibleByKey (should be True for Alice's contract) visibleAlice <- visibleByKey @MyContract aliceKey assert visibleAlice "visibleByKey should return True for Alice's contract" traceShowId "visibleByKey returned True for Alice's contract as expected" -- 9. Demonstrate visibleByKey for Bob (should be False as Bob is not a stakeholder) visibleBob <- visibleByKey @MyContract bob assert (not visibleBob) "visibleByKey should return False for Bob's contract (not a stakeholder)" traceShowId "visibleByKey returned False for Bob's contract as expected" -- 10. Demonstrate visibleByKey for a non-existent key (should be False) visibleNonExistent <- visibleByKey @MyContract nonExistentKey assert (not visibleNonExistent) "visibleByKey should return False for a non-existent key" traceShowId "visibleByKey returned False for a non-existent key as expected" return () ``` -------------------------------- ### Install Local Daml SDK on Linux/Mac Source: https://github.com/digital-asset/daml/blob/main/sdk/README.md Installs a local version of the Daml SDK (version 0.0.0) on Linux and Mac. Set the `version:` field in your Daml project to 0.0.0 to use this local installation. ```bash daml-sdk-head ``` -------------------------------- ### Install Additional SDK Versions Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/component-howtos/smart-contracts/assistant.rst Use 'daml install' to add specific SDK versions to your system. The version string can be found on the GitHub releases page. ```bash daml install ``` -------------------------------- ### Install and Sync Dev Environment on Windows Source: https://github.com/digital-asset/daml/blob/main/sdk/README.md Use these PowerShell commands to install and synchronize the development environment on Windows. The 'enable' step must be repeated in new PowerShell sessions. ```powershell .\dev-env\windows\bin\dadew.ps1 install . \dev-env\windows\bin\dadew.ps1 sync . \dev-env\windows\bin\dadew.ps1 enable ``` -------------------------------- ### Generate Java Code and Compile Quickstart Source: https://github.com/digital-asset/daml/blob/main/sdk/release/RELEASE.md Generates Java code from Daml models and compiles the quickstart project. It uses the party name extracted from the output.json file. ```sh dpm codegen-java && mvn compile exec:java@run-quickstart -Dparty=$(cat output.json | sed 's/["']//g' | sed 's/].*//') ``` -------------------------------- ### Start Jaeger Server with Docker Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/sdlc-howtos/applications/observe/open-tracing.rst Use this Docker command to start a Jaeger all-in-one server for collecting and visualizing traces. ```bash docker run --rm -it --name jaeger \ -p 16686:16686 \ -p 14250:14250 \ jaegertracing/all-in-one:1.22.0 ``` -------------------------------- ### DAML Example: fetchByKey and lookupByKey Scenarios Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/reference/daml/contract-keys.rst A comprehensive example demonstrating various success and failure scenarios for `fetchByKey` and `lookupByKey` operations in DAML. This snippet provides practical context for using contract keys. ```daml module Keys where import DA.Optional (Optional(..)) import qualified DA.Set as Set import qualified DA.Time as Time -- | A contract that can be fetched by key. template Asset with owner : Party issuer : Party symbol : Text amount : Decimal time : Time.Time where -- | The key for the Asset contract. key (owner, symbol) -- | The choice to transfer an asset. choice Transfer with newOwner : Party newAmount : Decimal do -- Ensure the new amount is not greater than the current amount. check (newAmount <= amount) -- Transfer the asset to the new owner. return Asset with {..} -- | A function to create an asset. createAsset : Party -> Party -> Text -> Decimal -> Time.Time -> Update (ContractId Asset) createAsset owner issuer symbol amount time = create Asset with { owner = owner, issuer = issuer, symbol = symbol, amount = amount, time = time } -- | A function to fetch an asset by its key. fetchAssetByKey : Party -> Text -> Update (Optional (ContractId Asset, Asset)) fetchAssetByKey owner symbol = do -- Attempt to fetch the asset by its key. maybeAsset <- lookupByKey @Asset (owner, symbol) case maybeAsset of Nothing -> return None Just contractId -> do -- If found, fetch the contract details. asset <- fetch contractId -- Return the contract ID and the asset. return $ Just (contractId, asset) -- | A function to transfer an asset using its key. transferAssetByKey : Party -> Text -> Party -> Decimal -> Update (Optional (ContractId Asset, Asset)) transferAssetByKey owner symbol newOwner newAmount = do -- Attempt to fetch the asset by its key. maybeAsset <- lookupByKey @Asset (owner, symbol) case maybeAsset of Nothing -> return None Just contractId -> do -- If found, fetch the contract details. asset <- fetch contractId -- Exercise the Transfer choice on the asset. exercise contractId Transfer with { newOwner = newOwner, newAmount = newAmount } -- Return the updated contract ID and asset. return $ Just (contractId, asset) -- | A function to check if an asset is visible by its key. visibleAssetByKey : Party -> Text -> Update Bool visibleAssetByKey owner symbol = visibleByKey @Asset (owner, symbol) ``` -------------------------------- ### Partial Application Example (Daml) Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/reference/daml/functions.rst Demonstrates partial application by applying only one argument to a function. ```daml halfTubeSurfaceArea = tubeSurfaceArea 1.0 -- halfTubeSurfaceArea : Decimal -> Decimal -- halfTubeSurfaceArea height = tubeSurfaceArea 1.0 height ``` -------------------------------- ### Troubleshoot Port Binding Issues (Linux Example) Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/component-howtos/application-development/dpm-sandbox.rst Example of using 'lsof -n -i' on Linux to identify processes listening on specific ports, useful for diagnosing 'Failed to bind to address' errors. ```none $ lsof -n -i ... java 707977 username 77u IPv6 67556378 0t0 TCP 127.0.0.1:6865 (LISTEN) ... ``` -------------------------------- ### Install Daml Assistant (Linux/macOS) Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/component-howtos/smart-contracts/assistant.rst Run this command to install the latest Daml SDK and Daml Assistant on Linux and macOS. You may need to restart your terminal for the changes to take effect. ```bash curl -sSL https://get.daml.com/ | sh -s 3.4.9 ``` -------------------------------- ### Start Daml Sandbox Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/sdlc-howtos/smart-contracts/upgrade/smart-contract-upgrades.rst Starts the Daml Sandbox, a simple ledger for testing. The `--json-api-port` flag is used to specify the port for the JSON API. ```bash > dpm sandbox --json-api-port 7575 Starting Canton sandbox. Listening at port 6865 Canton sandbox is ready. ``` -------------------------------- ### Install Daml Assistant with a specific version Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/component-howtos/smart-contracts/assistant.rst Use this command to install a specific version of the Daml Assistant, not the entire SDK. This is useful for managing assistant versions independently. ```bash daml install --install-assistant=yes ``` -------------------------------- ### Configure and Start Sandbox with DAR Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/tutorials/smart-contracts/dependencies.rst Configure the Canton sandbox to load a specific DAR file by creating a configuration file and then starting the sandbox. This is useful for testing smart contracts with external dependencies. ```shell cat < config.conf ``` ```shell dpm sandbox -c config.conf ``` -------------------------------- ### Daml Record Creation Example Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/source/sdk/sdlc-howtos/applications/integrate/grpc/daml-to-ledger-api.rst Demonstrates creating a value of the MyProductType Daml record. ```daml let myProduct = MyProductType with int64Field = 1 decimalField = 1.23 textFields = "hello" timeField = '2021-08-10T10:00:00Z' partyField = 'party1' boolField = True contractIdField = 'contractId1' ``` -------------------------------- ### View Sandbox Command Line Help Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/component-howtos/application-development/dpm-sandbox.rst Run this command to see all available command-line configuration options for the Sandbox. ```none dpm sandbox --help ``` -------------------------------- ### Run a Scala REPL Source: https://github.com/digital-asset/daml/blob/main/sdk/BAZEL.md Starts a Scala REPL with the specified library on the classpath. This is useful for interactive development and testing. ```bash bazel run //ledger/ledger-on-memory:ledger-on-memory_repl ``` -------------------------------- ### Get Ledger Time Example Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/tutorials/smart-contracts/constraints.rst Demonstrates how to retrieve the current ledger time within an Action context. `getTime` is an Action and cannot be evaluated as a pure expression. ```daml now <- getTime ``` -------------------------------- ### Daml Variant Creation Example Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/source/sdk/sdlc-howtos/applications/integrate/grpc/daml-to-ledger-api.rst Shows how to create values for the MySumType variant using its constructors. ```daml let mySum1 = MySumType MyConstructor1 123 let mySum2 = MySumType MyConstructor2 (456, "hello") ``` -------------------------------- ### Foldr - Right Fold with Initial Value Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/sharable/sdk/reference/daml/stdlib/DA-NonEmpty.rst Use `foldr` for a right-associative fold on a NonEmpty list, starting with an initial value. The example demonstrates summing elements with an initial value of 0. ```daml foldr : (a -> b -> b) -> b -> NonEmpty a -> b -- Example: foldr (+) 0 (NonEmpty 1 [2,3,4]) = 1 + (2 + (3 + (4 + 0))) ``` -------------------------------- ### Create a New Daml Project with Upgrade Template Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/sdlc-howtos/smart-contracts/upgrade/smart-contract-upgrades.rst Initialize a new Daml project using the `upgrades-example` template to explore multi-package build capabilities for smart contract upgrades. ```bash > dpm new upgraded-iou --template upgrades-example > cd upgraded-iou > tree . ├── multi-package.yaml ├── run-test.sh ├── interfaces │   ├── daml/... │   └── daml.yaml ├── main-v1 │   ├── daml/... │   └── daml.yaml ├── main-v2 │   ├── daml/... │   └── daml.yaml └── test ├── daml/... └── daml.yaml ``` -------------------------------- ### Build and Test Workflow Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/sdlc-howtos/smart-contracts/upgrade/smart-contract-upgrades.rst This sequence demonstrates a typical workflow for building and testing smart contracts, including modifying and rebuilding specific packages. ```bash > # Build all, run test > cd interfaces/; dpm build --enable-multi-package=no > cd ../main-v1/; dpm build --enable-multi-package=no > cd ../main-v2/; dpm build --enable-multi-package=no > cd ../test/; dpm build --enable-multi-package=no > cd .. > ./run-test.sh ``` ```bash > # Modify v2, run test > cd main-v2/ > ... modify main-v2 ... > dpm build --enable-multi-package=no > cd ../test/; dpm build --enable-multi-package=no > cd .. > # Modify test, run test > cd test/ > dpm build --enable-multi-package=no > cd .. > ./run-test.sh ``` -------------------------------- ### Daml Tuples Example Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/tutorials/smart-contracts/data.rst Demonstrates the creation and usage of tuples for grouping data, such as key-value pairs or coordinates. ```daml module Tuple where -- TUPLE_TEST_BEGIN tupleTest :: (Text, Int) tupleTest = ("hello", 1) coordTest :: (Decimal, Decimal, Decimal) coordTest = (1.0, 2.0, 3.0) -- TUPLE_TEST_END ``` -------------------------------- ### SimpleAsset Workflow Example Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/overview/explanations/ledger-model/ledger-integrity.rst Demonstrates a workflow where an asset is transferred and then later shown to an observer, illustrating potential concurrency issues with projections. ```daml test "Alice transfers EUR to Bob, then Bank shows Alice's EUR to Vivian" :: Script where (alice, bob, viewer, bank) <- (genParty "Alice", genParty "Bob", genParty "Vivian", genParty "Bank") let eur = EUR "100" alice `mustBe` alice bob `mustBe` bob viewer `mustBe` viewer bank `mustBe` bank // Alice transfers EUR to Bob aliceCreatesAsset eur "Alice" "Alice" "EUR" "100" let assetId = AssetId "Alice" "Alice" "EUR" "100" let transferCmd = TransferCmd with (assetId = assetId, to = bob) submit alice do create SimpleAsset with (owner = alice, issuer = alice, assetId = assetId, amount = eur) exercise (AssetKey assetId) transferCmd // Bank shows Alice's EUR to Vivian let presentCmd = PresentCmd with (viewer = viewer) submit bank do exercise (AssetKey assetId) presentCmd return () ``` -------------------------------- ### Install Required Pester Version Source: https://github.com/digital-asset/daml/blob/main/sdk/dev-env/windows/README.md Installs version 4.x of Pester if it's not already present. This script is available at `dev-env-windows/test/update-pester.ps1`. ```powershell PS C:\> ./test.ps1 ``` -------------------------------- ### Navigate to SDK Directory Source: https://github.com/digital-asset/daml/blob/main/sdk/README.md Change directory to the 'sdk' folder to access build-related files. ```bash cd sdk ``` -------------------------------- ### Check Pester Installation Source: https://github.com/digital-asset/daml/blob/main/sdk/dev-env/windows/README.md Verifies if Pester is installed on the Windows machine and displays its version. Version 4.x is required for running tests. ```powershell Get-InstalledModule -Name Pester ``` -------------------------------- ### sliceHexBytes Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/sharable/sdk/reference/daml/stdlib/DA-Crypto-Text.rst Extracts a portion of a byte encoded string from a start byte up to, but excluding, an end byte. Byte indexing starts at 1. ```APIDOC ## sliceHexBytes ### Description Extracts a portion of a byte encoded string from a start byte up to, but excluding, an end byte. Byte indexing starts at 1. ### Signature `sliceHexBytes BytesHex Int Int -> Either Text BytesHex` ``` -------------------------------- ### SBT Project Structure Example Source: https://github.com/digital-asset/daml/blob/main/sdk/BAZEL-JVM.md Illustrates a typical SBT project structure for a JVM component, showing the hierarchy of build files and source directories. ```text da ├── WORKSPACE └── my_component ├── build.sbt ├── module1 │ ├── build.sbt │ └── src │ ├── main │ │ └── scala │ │ └── com/daml/module │ │ ├── Main.scala │ │ ⋮ │ └── test │ └── scala │ └── com/daml/module │ ├── SomeSpec.scala │ ⋮ ├── module2 │ ├── build.sbt ⋮ ⋮ └── project ⋮ ``` -------------------------------- ### Daml Script Basic Submission Example Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/sharable/hoogle/daml-script-hoogle.txt A minimal example of a Daml Script submission using `actAs` and `submit` to create a contract. ```haskell actAs alice `submit` createCmd MyContract with party = alice ``` -------------------------------- ### Fine-Grained Bazel Project Structure Example Source: https://github.com/digital-asset/daml/blob/main/sdk/BAZEL-JVM.md Presents a fine-grained Bazel project structure, emphasizing small targets and packages for efficient incremental builds. ```text da ├── WORKSPACE └── my_component ├── BUILD.bazel ├── module1 │ ├── BUILD.bazel │ └── src │ ├── main │ │ └── scala │ │ └── com/daml/module │ │ ├── BUILD.bazel │ │ ├── Main.scala │ │ ⋮ │ └── test │ └── scala │ └── com/daml/module │ ├── BUILD.bazel │ ├── SomeSpec.scala │ ⋮ └── module2 ├── BUILD.bazel ⋮ ``` -------------------------------- ### Daml Lists Example Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/tutorials/smart-contracts/data.rst Shows how to instantiate and use lists of a single type, along with common list functions. ```daml module List where -- LIST_TEST_BEGIN listTest :: [Int] listTest = [1, 2, 3] empty :: [Int] empty = [] appendTest :: [Int] appendTest = listTest ++ [4, 5] headTest :: Int headTest = head listTest tailTest :: [Int] tailTest = tail listTest lengthTest :: Int lengthTest = length listTest mapTest :: [Int] mapTest = map (*2) listTest filterTest :: [Int] filterTest = filter (>1) listTest -- LIST_TEST_END ``` -------------------------------- ### Initialize Project and Check SDK Version Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/sdlc-howtos/smart-contracts/upgrade/smart-contract-upgrades.rst Initializes a new Daml project and checks the project's SDK version. Ensure you are using SDK 3.3.0 or higher for SCU support. ```bash mkdir -p v1/my-pkg cd v1/my-pkg dpm init dpm version ``` -------------------------------- ### SimpleDvP Workflow Example Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/sharable/overview/explanations/ledger-model/ledger-structure.rst This Daml Script encodes the entire workflow for the running DvP example, illustrating contract creation and exercise actions. ```daml module SimpleDvP where import Daml.Script import qualified DA.Set as Set -- | A simple asset that can be held by a party. -- The asset has a quantity and an issuer. template SimpleAsset with issuer : Party owner : Party quantity : Decimal where signatory issuer, owner ensure quantity > 0 choice TransferAsset : ContractId SimpleAsset with newOwner : Party newQuantity : Decimal -- The owner can transfer the asset to a new owner. -- The new quantity must be less than or equal to the current quantity. -- The issuer must also consent to the transfer. controller owner do let newAsset = SimpleAsset with owner = newOwner, quantity = newQuantity let transferredAsset = SimpleAsset with owner = owner, quantity = quantity - newQuantity create newAsset -- | A simple delivery versus payment workflow. simpleDvP : Scenario simpleDvP = do -- Setup parties alice <- getParty "Alice" bob <- getParty "Bob" bank1 <- getParty "Bank 1" bank2 <- getParty "Bank 2" -- Alice creates an asset of 1 EUR issued by Bank 1. asset1 <- submit bank1 do create SimpleAsset with issuer = bank1, owner = alice, quantity = 1.0 -- Bob creates an asset of 1 USD issued by Bank 2. asset2 <- submit bank2 do create SimpleAsset with issuer = bank2, owner = bob, quantity = 1.0 -- Alice wants to exchange her EUR asset for Bob's USD asset. -- She initiates the exchange by creating an "AcceptAndSettle" contract. -- This contract holds the two assets and the parties involved. acceptAndSettleId <- submit alice do create AcceptAndSettle with partyA = alice, partyB = bob, assetA = asset1, assetB = asset2 -- Bob accepts the exchange and settles the transaction. -- This consumes both assets and creates new assets with exchanged owners. submit bob do exercise acceptAndSettleId AcceptAndSettle.Settle -- Verify that the assets have been exchanged. -- Alice should now own the USD asset and Bob should own the EUR asset. asset1New <- query [alice, bob] asset1 asset2New <- query [alice, bob] asset2 assert (owner asset1New == bob) assert (owner asset2New == alice) -- | A contract that represents an agreement to exchange two assets. -- It holds the two assets and the parties involved. template AcceptAndSettle with partyA : Party partyB : Party assetA : ContractId SimpleAsset assetB : ContractId SimpleAsset where -- Anyone can view the contract. view partyA, partyB -- The contract can only be exercised by the parties involved. choice Settle : () -- The choice can only be exercised by partyA or partyB. controller partyA, partyB do -- Fetch the assets to be exchanged. assetAData <- fetch assetA assetBData <- fetch assetB -- Create new assets with exchanged owners. let newAssetA = SimpleAsset with issuer = issuer assetAData, owner = partyB, quantity = quantity assetAData let newAssetB = SimpleAsset with issuer = issuer assetBData, owner = partyA, quantity = quantity assetBData -- Consume the old assets and create the new ones. create newAssetA create newAssetB ``` -------------------------------- ### Example IOU Data Structure Source: https://github.com/digital-asset/daml/blob/main/sdk/release/RELEASE.md Example JSON output representing an IOU asset on the ledger, including issuer, owner, currency, amount, and observers. ```json { "0": { "issuer": "EUR_Bank::NAMESPACE", "owner": "Alice::NAMESPACE", "currency": "EUR", "amount": 100.0, "observers": [] } } ``` -------------------------------- ### Build All Packages from Subdirectory Source: https://github.com/digital-asset/daml/blob/main/sdk/unreleased/multi-package.md Demonstrates building from a subdirectory (`libs/`). Without specifying the root `multi-package.yaml`, only packages defined in the local `libs/multi-package.yaml` are built. ```bash > cd libs/ > daml build --all Building "my-lib-helper"... Building "my-lib"... # Main is *not* built, because libs/multi-package.yaml was used ``` -------------------------------- ### Left Fold Starting with List Head (Daml) Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/sharable/hoogle/daml-base-hoogle.txt Use `foldl1` for a left fold that starts with the head of a non-empty list. Returns `Optional a` for empty lists. ```Daml foldl1 :: (a -> a -> a) -> [a] -> Optional a ``` -------------------------------- ### Java Security Exception Example Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/component-howtos/application-development/dpm-sandbox.rst Example of a Java SecurityException related to JCE authentication of the BC provider, often encountered when using Oracle JDK with Canton. ```none java.lang.SecurityException: JCE cannot authenticate the provider BC at java.base/javax.crypto.JceSecurity.getInstance(JceSecurity.java:150) at java.base/javax.crypto.Mac.getInstance(Mac.java:272) at com.digitalasset.canton.crypto.provider.jce.JcePureCrypto.$anonfun$computeHmacWithSecretInternal$1(JcePureCrypto.scala:873) (...) ``` -------------------------------- ### Configure Bazel for Windows Source: https://github.com/digital-asset/daml/blob/main/sdk/README.md Create a local Bazel configuration file to enable Windows-specific build settings. ```bash echo "build --config windows" > .bazelrc.local ``` -------------------------------- ### Synchronize Documentation Source: https://github.com/digital-asset/daml/blob/main/sdk/README.md Run this script from the `/sdk` folder to keep the manually written and auto-generated documentation in sync. It's recommended to run this before pushing changes. ```bash ./ci/synchronize-docs.sh ``` -------------------------------- ### Valid Upgrade File Structure Example Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/manually-written/sdk/reference/smart-contract-upgrades.rst Illustrates a file structure where package v2 can be a valid upgrade of package v1, assuming the content of A.daml is compatible. ```text ├── v1 │ ├── daml │ │ └── A.daml │ └── daml.yaml └── v2 ├── daml │ ├── A.daml │ └── B.daml └── daml.yaml ``` -------------------------------- ### Right Fold Starting with List Last Element (Daml) Source: https://github.com/digital-asset/daml/blob/main/sdk/docs/sharable/hoogle/daml-base-hoogle.txt Use `foldr1` for a right fold that starts with the last element of a non-empty list. Returns `Optional a` for empty lists. ```Daml foldr1 :: (a -> a -> a) -> [a] -> Optional a ``` -------------------------------- ### Building Individual Repositories Source: https://github.com/digital-asset/daml/blob/main/sdk/unreleased/multi-package.md Commands to build all packages within the 'library-repository' and then 'application-repository' separately. ```bash > cd library-repository > daml build --all ... Building "library-logic"... Building "library-tests"... Done. > cd application-repository > daml build --all ... Building "application-logic"... Building "application-tests"... Done. ```