daml/language-support/scala/examples/quickstart-scala
Moritz Kiefer 2c10c4444b
Extend daml new to accept template as an option (#6877)
* Extend `daml new` to accept template as an option

The two positional arguments keep confusing users so this PR changes
things to allow the template to be passed via `--template`. Using a
positional argument still works so this is not breaking.

I’ve updated all docs to use the less confusing syntax.

changelog_begin

- [DAML Assistant] You can now use ``daml new project-name
  --template=template-name`` instead of ``daml new project-name
  template-name``. The old CLI syntax continues to be supported.

changelog_end

* Update docs/source/getting-started/index.rst

Co-authored-by: Martin Huschenbett <martin.huschenbett@posteo.me>

Co-authored-by: Martin Huschenbett <martin.huschenbett@posteo.me>
2020-07-27 16:30:48 +02:00
..
application/src/main Ledger id requirement (#6323) 2020-06-12 15:00:32 +00:00
project Scala codegen examples: removing bintray repository, relying on daml.yaml and -Dda.sdk.version (#5436) 2020-04-06 06:33:30 +00:00
build.sbt Commenting out local maven repository config (#5452) 2020-04-06 11:55:13 -04:00
daml.yaml Use com.daml as root package (#5343) 2020-04-05 19:49:57 +02:00
README.md Extend daml new to accept template as an option (#6877) 2020-07-27 16:30:48 +02:00

quickstart-scala example

This example demonstrates how to:

  • set up and configure Scala codegen (see codegen configuration in the ./daml.yaml)
  • instantiate a contract and send a corresponding create command to the ledger
  • how to exercise a choice and send a corresponding exercise command
  • subscribe to receive ledger events and decode them into generated Scala ADTs

All instructions below assume that you have DAML SDK installed. If you have not installed it yet, please follow these instructions: https://docs.daml.com/getting-started/installation.html

Create a quickstart-scala project

daml new ./quickstart-scala --template quickstart-scala

This should output:

Created a new project in "./quickstart-scala" based on the template "quickstart-scala".

Where:

  • ./quickstart-scala is a project directory name
  • quickstart-scala is a project template name, to see the entire list of available templates, run: daml new --list

Compile the DAML project

The DAML code for the IOU example is located in the ./daml folder. Run the following command to build it:

$ cd ./quickstart-scala
$ daml build

this should output:

Compiling quickstart to a DAR.
Created .daml/dist/quickstart-0.0.1.dar.

Generate Scala classes representing DAML contract templates

$ daml codegen scala

This should generate scala classes in the ./scala-codegen/src/main/scala directory. See codegen configuration in the daml.yaml file:

...
codegen:
  scala:
    package-prefix: com.daml.quickstart.iou.model
    output-directory: scala-codegen/src/main/scala
    verbosity: 2

Start Sandbox

This examples requires a running sandbox. To start it, run the following command:

$ daml sandbox ./.daml/dist/quickstart-0.0.1.dar

where ./.daml/dist/quickstart-0.0.1.dar is the DAR file created in the previous step.

Compile and run Scala example

Run the following command from the quickstart-scala folder:

$ sbt "application/runMain com.daml.quickstart.iou.IouMain localhost 6865"

If example completes successfully, the above process should terminate and the output should look like this:

<Sent and received messages>
...
11:54:03.865 [run-main-0] INFO - Shutting down...
...
[success] Total time: 7 s, completed Sep 12, 2019, 11:54:04 AM

To run the quickstart-scala as a standalone project (not part of the DAML project), you can specify da.sdk.version JVM system properties:

$ sbt -Dda.sdk.version=<DA_SDK_VERSION> "application/runMain com.daml.quickstart.iou.IouMain localhost 6865"