# Some contracts are not being created when exercising a choice

**URL:** <https://forum.canton.network/t/some-contracts-are-not-being-created-when-exercising-a-choice/4198>\
**Category:** App Development\
**Tags:** daml, contract, choices\
**Created:** [March 24, 2022, 7:43pm UTC](https://forum.canton.network/t/some-contracts-are-not-being-created-when-exercising-a-choice/4198 "2022-03-24T19:43:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![cohen.avraham](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cohen.avraham](https://forum.canton.network/u/cohen.avraham)\
**Post date:** [March 24, 2022, 7:43pm UTC](https://forum.canton.network/t/some-contracts-are-not-being-created-when-exercising-a-choice/4198/1 "2022-03-24T19:43:24Z")

</div>

G-d willing

I am seeing a very strange behavior in Daml.  
In the navigator - I am exercising a choice which create 3 contracts. However, only the first one is created.  
But when I am exercising it through a scenario, all is working fine.

Did anyone experience such a thing?

---

<div class="post-metadata">

**Author:** ![Leonid\_Rozenberg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/leonid_rozenberg/32/48_2.png) [@Leonid\_Rozenberg](https://forum.canton.network/u/Leonid_Rozenberg)\
**Post date:** [March 25, 2022, 1:51am UTC](https://forum.canton.network/t/some-contracts-are-not-being-created-when-exercising-a-choice/4198/2 "2022-03-25T01:51:37Z")

</div>

@cohen.avraham Do the contracts have the same entitlements?

---

<div class="post-metadata">

**Author:** ![cohen.avraham](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cohen.avraham](https://forum.canton.network/u/cohen.avraham)\
**Post date:** [March 25, 2022, 7:43am UTC](https://forum.canton.network/t/some-contracts-are-not-being-created-when-exercising-a-choice/4198/3 "2022-03-25T07:43:57Z")

</div>

G-d willing

Hi @Leonid_Rozenberg, thanks for your response, regarding your question, of course, I set the contracts with the same values as in the script.  
I was checking that several times and with no luck.

Here is the code from the choice I am running:

```haskell
nonconsuming choice AcceptBidInvitationFromIssuer: ContractId IssuerBankerBidRelationship
      with
        bidIdentifier: Text
      controller owner
        do  
          (invitationCid, invitation) <- fetchByKey @BidInvitationOfferToBanker (issuer, owner, bidIdentifier)
          assertMsg "The banker dealer does not match" (invitation.banker == owner)
          assertMsg "The wrong bid was found" (invitation.bidIdentifier == bidIdentifier)
          relationshipCid <- exercise invitationCid AcceptBidInvitationOfferToBanker

          forA_ investors $ \invest ->
            create BidInvitationOfferToInvestor with interestRate=invitation.interestRate,periodInMonths=invitation.periodInMonths,banker=owner; investor=invest,expiryDate=invitation.expiryDate; amount=invitation.amount, minProposal=invitation.minProposal,..

          exercise relationshipCid InitializeBidAcceptance
          return relationshipCid

```

As said, the first contract in the following line is created:

```haskell
          relationshipCid <- exercise invitationCid AcceptBidInvitationOfferToBanker

```

However, the rest is not created in Navigator. And I used debug just to make sure that the list of “investors” is not empty (actually there are 4 investors in the list).

Here is a screenshot of the script form the Visual Code:

 ![image](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/f/fb6048224b71c3b53ab0ab6e1e85fb22c17ade7f.png)

And here is the screenshot from the Navigator, where the contract “BidInvitationOfferToInvestor”:

 ![image](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/3/34ac8503db836414847979beaa3423403d3c8e7d.jpeg)

---

<div class="post-metadata">

**Author:** ![Gary\_Verhaegen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gary_verhaegen/32/81_2.png) [@Gary\_Verhaegen](https://forum.canton.network/u/Gary_Verhaegen)\
**Post date:** [March 25, 2022, 11:02am UTC](https://forum.canton.network/t/some-contracts-are-not-being-created-when-exercising-a-choice/4198/4 "2022-03-25T11:02:35Z")

</div>

Hi @cohen.avraham,

Scripts running in Daml Studio (the VSCode editor) do not run against an external ledger, they run against an internal in-memory one. Therefore, there is no link between the state of your ledger in the IDE and the state presented by Navigator (which _is_ connected to a real, separate ledger).

The most plausible explanation here is that, in your scripts, you set up `investors` as a list with four elements, but, in the “real” ledger, it’s an empty list.

Could you perhaps share a screenshot of the Navigator showing the details of the relevant contract? (From your code snippet it looks like `investors` is a property of the contract on which `AcceptBidInvitationFromIssuer` is a choice, but I can’t see which template that is.)

---

<div class="post-metadata">

**Author:** ![cohen.avraham](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cohen.avraham](https://forum.canton.network/u/cohen.avraham)\
**Post date:** [March 28, 2022, 11:15am UTC](https://forum.canton.network/t/some-contracts-are-not-being-created-when-exercising-a-choice/4198/5 "2022-03-28T11:15:47Z")

</div>

> [@Gary\_Verhaegen](#):
>
> Could you perhaps share a screenshot of the Navigator showing the details of the relevant contract? (From your code snippet it looks like `investors` is a property of the contract on which `AcceptBidInvitationFromIssuer` is a choice, but I can’t see which template that is.)

Sure thing @Gary_Verhaegen , the `AcceptBidInvitationFromIssuer`is choice of the Banker template I created.  
Here is the Banker template (without its choices):

```haskell
template Banker
  with
    issuer: Party
    owner: Party
    investors: [Party]
  where
    signatory owner
    observer investors

```

I have a script running (which is defined in the daml.yaml file) that sets the list of the investors to the banker:

```haskell
  bankLeumiBrokerCid <- submit leumiBankBroker do
    exerciseCmd bankLeumiBrokerCid OnboardInvestor with investor=meitavDash
  bankLeumiBrokerCid <- submit leumiBankBroker do
    exerciseCmd bankLeumiBrokerCid OnboardInvestor with investor=migdal
  bankLeumiBrokerCid <- submit leumiBankBroker do
    exerciseCmd bankLeumiBrokerCid OnboardInvestor with investor=menura
  bankLeumiBrokerCid <- submit leumiBankBroker do
    exerciseCmd bankLeumiBrokerCid OnboardInvestor with investor=harel

```

And you can see from the following screenshot that the list of investors is not empty at the navigator:

 ![image](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/d/d1c1cd3cc26f9ea28fa112e6abfca84e7f09910a.png)

Looking forward to your answer…

---

<div class="post-metadata">

**Author:** ![Gary\_Verhaegen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gary_verhaegen/32/81_2.png) [@Gary\_Verhaegen](https://forum.canton.network/u/Gary_Verhaegen)\
**Post date:** [March 28, 2022, 11:43am UTC](https://forum.canton.network/t/some-contracts-are-not-being-created-when-exercising-a-choice/4198/6 "2022-03-28T11:43:34Z")

</div>

Thanks!

Next thing I would check, then, is that all of those are proper parties initialized in the ledger Navigator runs against. I don’t think we check that a party exists when it is just added to a list.

To that end, can you confirm that, in the Navigator:

1. you can create a single-signatory contract for each of those investors.
2. you can observe the consequences of the `exercise relationshipCid InitializeBidAcceptance` line.

---

<div class="post-metadata">

**Author:** ![cohen.avraham](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cohen.avraham](https://forum.canton.network/u/cohen.avraham)\
**Post date:** [March 28, 2022, 12:18pm UTC](https://forum.canton.network/t/some-contracts-are-not-being-created-when-exercising-a-choice/4198/7 "2022-03-28T12:18:59Z")

</div>

> [@Gary\_Verhaegen](#):
>
> Next thing I would check, then, is that all of those are proper parties initialized in the ledger Navigator runs against. I don’t think we check that a party exists when it is just added to a list.

Regarding the other things you mentioned, like creating a single-signatory contract, well, it was created - you can see that in my first screenshot from the navigator.  
Well, all the bankers and investors are listed on the login screen of the navigator:

 ![image](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/9/93dcecfae7bd04206c7feb1b7530178137c34d35.png)

And for the investors, they are initialized in the main script as well:

````haskell
  meitavDash <- allocatePartyWithHint "Meitav Dash" (PartyIdHint "Meitav Dash")
  migdal <- allocatePartyWithHint "Migdal" (PartyIdHint "Migdal")
  menura <- allocatePartyWithHint "Menura" (PartyIdHint "Menura")
  harel <- allocatePartyWithHint "Harel" (PartyIdHint "Harel")```
````

---

<div class="post-metadata">

**Author:** ![Gary\_Verhaegen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gary_verhaegen/32/81_2.png) [@Gary\_Verhaegen](https://forum.canton.network/u/Gary_Verhaegen)\
**Post date:** [March 28, 2022, 12:51pm UTC](https://forum.canton.network/t/some-contracts-are-not-being-created-when-exercising-a-choice/4198/8 "2022-03-28T12:51:00Z")

</div>

> [@cohen.avraham](#):
>
> Regarding the other things you mentioned, like creating a single-signatory contract, well, it was created - you can see that in my first screenshot from the navigator.

Apologies if I’m being dense here, but I’m not seeing an example of a single-signatory contract _per investor_ in any of your screenshots.

While reviewing the screenshots, however, I did notice that, in the IDE screenshot you shared, all of those `BidInvitationOfferToInvestor` contracts are **archived**. I suspect something else happens after their creation to archive them, either the `InitializeBidAcceptance` choice or the rest of your init script.

Archived contracts are not shown in Navigator.

Do you have any reason to believe these contracts _should not_ be archived?

---

<div class="post-metadata">

**Author:** ![cohen.avraham](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cohen.avraham](https://forum.canton.network/u/cohen.avraham)\
**Post date:** [March 28, 2022, 1:56pm UTC](https://forum.canton.network/t/some-contracts-are-not-being-created-when-exercising-a-choice/4198/9 "2022-03-28T13:56:19Z")

</div>

Here is an example of a single-signatory contract of the investor

 ![image](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/e/eb080c9ab4e911310fa7384b770152b8b520e3f5.png)

The thing is, the behavior is not consistent. Sometimes it does create the invitation contract and sometimes it doesn’t.  
I can share with you the entire code of what I did, and you can see it for yourself. How about that?

---

<div class="post-metadata">

**Author:** ![Gary\_Verhaegen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gary_verhaegen/32/81_2.png) [@Gary\_Verhaegen](https://forum.canton.network/u/Gary_Verhaegen)\
**Post date:** [March 28, 2022, 2:09pm UTC](https://forum.canton.network/t/some-contracts-are-not-being-created-when-exercising-a-choice/4198/10 "2022-03-28T14:09:44Z")

</div>

If you feel comfortable sharing the entire code publicly here, sure. Preferably in the form of a public GitHub repo or similar.

If you don’t, and you meant to share the code privately with me only, then I’m afraid that requires a support contract with Digital Asset and you’ll have to go through our customer support ticket process (and possibly the sales team to become a customer first, depending on your current status on that front).

---

<div class="post-metadata">

**Author:** ![cohen.avraham](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cohen.avraham](https://forum.canton.network/u/cohen.avraham)\
**Post date:** [March 29, 2022, 10:44am UTC](https://forum.canton.network/t/some-contracts-are-not-being-created-when-exercising-a-choice/4198/11 "2022-03-29T10:44:08Z")

</div>

Hi @Gary\_Verhaegenm I have opened a ticket (00001542)  
Hopefully, once I will understand the problem, I will share my thoughts and mistakes from it, so other can learn as well.
