# Make a contract visible to all parties

**URL:** <https://forum.canton.network/t/make-a-contract-visible-to-all-parties/4739>\
**Category:** App Development\
**Tags:** daml, canton\
**Created:** [June 15, 2022, 2:51pm UTC](https://forum.canton.network/t/make-a-contract-visible-to-all-parties/4739 "2022-06-15T14:51:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meriam\_Lachkar](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/meriam_lachkar/32/3999_2.png) [@Meriam\_Lachkar](https://forum.canton.network/u/Meriam_Lachkar)\
**Post date:** [June 15, 2022, 2:51pm UTC](https://forum.canton.network/t/make-a-contract-visible-to-all-parties/4739/1 "2022-06-15T14:51:05Z")

</div>

I have a contract I would like to make visible to all participants.

```haskell
template Registration
  with 
    admin: Party
    public: Party
  where 
    signatory admin
    observer public

```

I have created a `public` party on all participants using a [previous post](https://discuss.daml.com/t/public-party-and-reference-data/1802), and I added the `readAs` right to all the parties that need to see this contract.  
When using the navigator, those parties cannot see this contract:

```haskell
users.ledger_api.acs.of_party(myUser)
res9: Seq[com.digitalasset.canton.admin.api.client.commands.LedgerApiTypeWrappers.WrappedCreatedEvent] = List()

```

```haskell
@ users.ledger_api.users.rights.list("myUser")
res10: UserRights = UserRights(
  actAs = Set(
    "collector1::12209ef651220a793b7f0abb80ec8667af95da3dc54629e934c8f3e588916a47877a"
  ),
  readAs = Set(
    "public::12209ef651220a793b7f0abb80ec8667af95da3dc54629e934c8f3e588916a47877a"
  ),
  participantAdmin = false
)

```

I have two questions:

- Is it possible to observe this public contract without adding every party as an observer ?
- If this is possible, what should add to my code / user creation, to make this contract visible ?

Thanks

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [June 15, 2022, 2:58pm UTC](https://forum.canton.network/t/make-a-contract-visible-to-all-parties/4739/2 "2022-06-15T14:58:59Z")

</div>

Your code seems perfectly fine here. The issue in in Navigator. The problem is that it only shows you contracts visible to the primary party of your user even if your user has `readAs` claims for other parties, see [Navigator user login does not reflect the correct access - #2 by cocreature](https://discuss.daml.com/t/navigator-user-login-does-not-reflect-the-correct-access/4609/2) for more details.

That limitation doesn’t apply if you read, e.g., via the JSON API. That’s what create-daml-app does.

---

<div class="post-metadata">

**Author:** ![Meriam\_Lachkar](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/meriam_lachkar/32/3999_2.png) [@Meriam\_Lachkar](https://forum.canton.network/u/Meriam_Lachkar)\
**Post date:** [June 20, 2022, 9:51am UTC](https://forum.canton.network/t/make-a-contract-visible-to-all-parties/4739/3 "2022-06-20T09:51:51Z")

</div>

thanks for you answer.

I have a similar issue in my test scripts.

```haskell
test_create_expert = script do 
    ledgerParties <- allocateParties
    -- for debugging
    expertId <- validateUserId $ toUserId "Expert"
    rights <- listUserRights expertId
    debug rights
    registrationCid <- createExpert ledgerParties.admin ledgerParties.public ledgerParties.expert 
    pure()

```

But I m getting a right error:

```haskell
Script execution failed on commit at Test.Common:12:30:
  Attempt to fetch or exercise a contract not visible to the reading parties.
  Contract: #0:0 (Registration:Registration)
  actAs: 'Expert'
  readAs:
  Disclosed to: 'Bank', 'Public'

Trace: 
  [CanActAs 'Expert',CanReadAs 'Public']

```

The user Expert is created with `CanReadAs = Public` right and the contract is visible to Public.

I don’t understand what’s missing. Can you help me ?  
Thanks

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [June 20, 2022, 10:04am UTC](https://forum.canton.network/t/make-a-contract-visible-to-all-parties/4739/4 "2022-06-20T10:04:19Z")

</div>

How is `createExpert` defined?

---

<div class="post-metadata">

**Author:** ![Meriam\_Lachkar](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/meriam_lachkar/32/3999_2.png) [@Meriam\_Lachkar](https://forum.canton.network/u/Meriam_Lachkar)\
**Post date:** [June 20, 2022, 10:09am UTC](https://forum.canton.network/t/make-a-contract-visible-to-all-parties/4739/5 "2022-06-20T10:09:09Z")

</div>

```haskell
createExpert: Party -> Party -> Party -> Script (ContractId ExpertAccount)
createExpert admin public expert = do
  registrationCid <- submit admin $ createCmd (Registration admin public)
  expertAccountRequestCid <- submit expert $ exerciseCmd registrationCid SubmitExpertAccountRequest with ..
  submit admin $ exerciseCmd expertAccountRequestCid $ AcceptExpertAccount

```

With a simpler code where I only do a fetch, it fails too

```haskell
createExpert admin public expert = do
  registrationCid <- submit admin $ createCmd (Registration admin public)
  Some t <- queryContractId public registrationCid
  debug t
  result <- queryContractId expert registrationCid
  debug result

```

I m getting the following logs

```haskell
 Registration {admin = 'Admin', public = 'Public'}
 None

```

I m using the code provided in create-daml-app to create users with public read access.

```haskell
getOrCreateUser alias publicM = do
  userId <- validateUserId $ toUserId alias
  try
    getUser userId
  catch
    UserNotFound _ -> do
      p <- allocateParty alias
      let u = User userId (Some p)
      createUser u $ CanActAs p :: [CanReadAs public | Some public <- [publicM]]
      pure u

```

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [June 20, 2022, 12:24pm UTC](https://forum.canton.network/t/make-a-contract-visible-to-all-parties/4739/6 "2022-06-20T12:24:28Z")

</div>

I think you might have gotten confused by the distinction between users and parties and their relation to each other.

Each party can only ever see contracts that are visible to it. So `queryContractId expert …` is never going to show contracts `expert` is not a stakeholder on.

Users build on top of that: Each user has the right to act/read as some parties. This is particularly useful when working with ledgers that require authorization: You give someone a token that allows them to act as a user and you can then dynamically change which parties that user is authorized to act as. However, each request is still scoped to a set of parties not a set of users. The participant then checks that your user has the right to act/read as those parties.

So in your example you need to use `submitMulti [expert] [public]` and `queryContractId public` to get contracts visible to `public`.

---

<div class="post-metadata">

**Author:** ![a\_putkov](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/a_putkov/32/2971_2.png) [@a\_putkov](https://forum.canton.network/u/a_putkov)\
**Post date:** [June 21, 2022, 3:47pm UTC](https://forum.canton.network/t/make-a-contract-visible-to-all-parties/4739/7 "2022-06-21T15:47:02Z")

</div>

@Meriam_Lachkar,  
As an alternative to `submitMulti [expert] [public]` you can use `submitUser expertId`. `submitUser` is arguably preferable in test scripts for client app workflows centered around users rather than parties, as it allows to test whether user rights have been assigned correctly.

@cocreature,  
Since the client app workflows in Daml 2+ are likely to be centered around users rather than parties, do you think it would be possible and useful to introduce into Daml Script `queryUser`, `queryFilterUser`, `queryContractIdUser` and `queryContractKeyUser` by analogy with `submitUser`?
