Error: Attempt to fetch or exercise a contract not visible to the committer
Mod note: As of SDK 1.5.0 Scenarios have been superseded by the more powerful Daml Script. We now recommend using that for all purposes. For more information, and to learn how to use Script please check out @Andreas’ post on our blog.
Here is my code
template Attandance
with
systemUser : Party
associate : Optional Party
punchInTime : Optional Time
punchOutTime :Optional Time
where
signatory systemUser
nonconsuming choice PunchIn
: ContractId Attandance
with
currentTime : Time
controller associate
do
create this with punchInTime = Some currentTime
nonconsuming choice PunchOut
: ContractId Attandance
with
currentTime : Time
controller associate
do
create this with punchOutTime = Some currentTime
Here is my scenario of update punchIn
setup = do
systemUser <- getParty "Alice"
associate <- getParty "Bob"
atid <- submit systemUser do
create Attandance
with
systemUser
associate = None
punchInTime = None
punchOutTime = None
submit associate do
exercise asid PunchIn with
currentTime <- getTime
return()
Attempt to fetch or exercise a contract not visible to the committer.
** Contract: #2:0 (Attendence:Attandance)**
** Committer: 'Bob**
** Disclosed to: 'Alice**
I know why this error occur because systemUser create Attendance and associate exercise the choice but systemUser has to create attendance and associate PunchIn or PunchOut, I make “associate” observer, but it not solved.
Looks like you need to take care of two things.
Firstly, you need to actually pass the associate to the Attendance contact, by setting associate = Some associate.
Secondly, you need to declare the associate as an observer of a contract, by stating observer associate underneath the signatory line of the contract.
associate entity enters only in Attendance when he PunchIn,
And I create associate as observer but it dont work.
I’m afraid you’re going to have to somehow pass in your associate, or the contract will not be visible to them.
DAML contracts are private; you have to explicitly declare the parties that can see them. If a party needs to be able to exercise a choice on a contract, the signatory first needs to make them an observer.
In this case, you need to pass in your associate before punching in or out. If the associate is unknown when the contract is created, you’ll need a kind of two-phase flow, in which the signatory can exercise a choice to add an associate to the contract.
Could you post an example, in particular how you create the Attendance instance and specify the associate. If it is the same as what you originally posted, then
associate = None
does not specify a party as the associate` on that contract.