Best practices for adding contract keys to existing model

Hey DAMLer’s.

Last week I worked with @anthony and @bernhard to discuss how to best pass around state in React using router props.

We came to the conclusion that it would be most stable to add contract keys --> pass them as route parameters --> query by the template and contract key to retrieve the specific contract.

I have read through the Contract Keys documentation but am looking for other examples to better understand how contract keys work.

When I tried adding contract keys to our adaptation of the ex-bond-issuance repo, I was able to generate a .dar file, but when I spun up the application in Sandbox, it was clear that the init-script: DA.RefApps.Bond.Test.MarketSetupScript:setupMarket had never run.

In retrospect, I am surprised that I was able to generate a .dar file without any errors while the market setup script fails to initiate the ledger.

There seem to be more downstream consequences than specifying a key, maintainer, and data type for the particular contracts that I would like to have a stable reference to (for visualization purposes).

Are there any other resources out there that can help me to correctly add contract keys to an existing model?

1 Like

Hi @jamesljaworski85,

It’s not clear to me what error you are facing. In general, the sandbox (or any other ledger) does not really have any notion of an init script, and loading a DAR file does not execute any code by itself.

The one thing that does have a notion of an init script is the daml start command. If you spin up your sandbox using anything else, you have to execute any script you want to be executed yourself.

If you are using daml start, please share your daml.yaml configuration along with any error message you got as output from daml start.

1 Like

Hey @Gary_Verhaegen. Thanks for the response.

I am going to collect some more information to post a bit more context. For now here is my daml start and my daml.yaml

daml start --sandbox-option --address=localhost --sandbox-option -w --open-browser no

dk-version: 1.7.0
name: bond-issuance
source: src/main/daml
init-script: DA.RefApps.Bond.Test.MarketSetupScript:setupMarket
sandbox-options:
  - --ledgerid=bond-issuance
parties:
  - Operator
  - Regulator
  - AuctionAgent
  - Bank1
  - Bank2
  - Bank3
  - CSD
  - Issuer
  - CentralBank
version: 2.0.0
dependencies:
  - daml-prim
  - daml-stdlib
  - daml-script
  - daml-trigger
  - target/finlib-1.7.0.dar
build-options:
  - '--ghc-option'
  - '-Werror'
  - '--ghc-option'
  - '-Wunused-binds'

The confusion for me was that I didn’t get any errors - but rather it was clear that the init-script: DA.RefApps.Bond.Test.MarketSetupScript:setupMarket didn’t run fully.

I am going to try and recreate the error tomorrow morning and post some more detail.

1 Like