How to add a Party as an observer to an active Contract in DAML

I have issued a contract (alice) and allocated an owner Party (bob) (both Issuer and Owner can see the Contract). How do I add a new Party (fred) as an observer to the active contract without transferring ownership?

Hi @bjmacd,

Adding an observer is an update operation such that it requires a choice that would consume the currently active contract and create a new one having the new Party (fred) added as an observer.
I’m not sure if it is the example you are following (owner and issuer are not concepts that Daml is aware of), but the Iou example has a choice just to do this:

template Iou
  with
    issuer : Party
    owner : Party
    ...
    observers : [Party]
  where
    signatory issuer, owner
    observer observers
    ...
    choice Iou_AddObserver : IouCid
      with
        newObserver : Party
      controller owner
      do create this with observers = newObserver :: observers

Thanks you for your example, I found it easier to understand then the provided Iou example, so I have this working now. My observation is adding a party to the “observers” list on the contract, makes them an observer to the contract. I also want to be able to remove a party as an observer and tried the following code, which does remove the party from the “observers” list in the contract, but the party is still an observer. Any help would be appreciated, thanks :slight_smile:

choice DelObservers : ContractId Register
  with
    delObserver : Party
  controller owner
  do
    create this with
      observers = delete delObserver observers

What do you mean by it is not removed as an observer? As it was an observer before, it stays a witness for the contract until it get’s archived. You can look at a more granular view of the disclosure on the table view in Daml Studio if you enable the show detailed disclosure option.

Expanding on @Mate_Varga’s answers: Keep in mind that Daml contracts are immutable. You can never change the observers of an existing contract. Both adding observers and removing observers archive the existing contract and create a new one instead of modifying the observers of the original contract.

1 Like

Git it thanks. I am using a create above and beleive this archives the active contract and creates a new version with the change, and as mentioned, I can see the party has been removed from the “Observers” list

Thanks for the hint. After removing the party as above and with disclosure on, the parties status has changed from “O” to “W”, so the party is now a witness, so should not be able to query the contract anymore. This is what I am after, thanks