Error under setup in line 9 - can someone help?
I have a similar issue
module Main where
import Token
import UserAdmin
import Daml.Script
setup : Script ()
setup = script do
alice <- allocatePartyWithHint "Alice" (PartyIdHint "Alice")
bob <- allocatePartyWithHint "Bob" (PartyIdHint "Bob")
charlie <- allocatePartyWithHint "Charlie" (PartyIdHint "Charlie")
userAdmin <- allocatePartyWithHint "UserAdmin" (PartyIdHint "UserAdmin")
aliceIssuer <- submit userAdmin do
createCmd Issuer
with
userAdmin = userAdmin
issuer = alice
originalToken <- submit alice do
exerciseCmd aliceIssuer MintToken
with
description = "Cat Pic 1"
initialPrice = 100.00
currency = "USD"
royaltyRate = 0.05
thumbnail=""
bobOffer <- submit alice do
exerciseCmd originalToken Offer
with
newOwner = bob
price = 200.00
bobRequest <- submit bob do
createCmd OwnerRequest
with
userAdmin = userAdmin
owner = bob
reason = "I've got connections"
bobOwner <- submit userAdmin do
exerciseCmd bobRequest GrantOwnerRights
charlieRequest <- submit charlie do
createCmd OwnerRequest
with
userAdmin = userAdmin
owner = charlie
reason = "FOMO"
charlieOwner <- submit userAdmin do
exerciseCmd charlieRequest GrantOwnerRights
(bobToken, _, _) <- submit bob do
exerciseCmd bobOwner AcceptTokenAsNewOwner
with
offerId = bobOffer
charlieOffer <- submit bob do
exerciseCmd bobToken Offer
with
newOwner = charlie
price = 300.00
submit charlie do
exerciseCmd charlieOwner AcceptTokenAsNewOwner
with
offerId = charlieOffer
return ()
Can you share the error message you are seeing?
setup
: Script ()
Defined at /Users/kr.aalle/Desktop/new_nft/nft/daml/Main.daml:9:1
Script execution failed on commit at Main:21:20:
Attempt to fetch or exercise a contract not visible to the reading parties.
Contract: #0:0 (UserAdmin:Issuer)
actAs: 'Alice'
readAs:
Disclosed to: 'UserAdmin'
Ledger time: 1970-01-01T00:00:00Z
Partial transaction:
Committed transactions:
TX 0 1970-01-01T00:00:00Z (Main:15:18)
#0:0
│ disclosed to (since): 'UserAdmin' (0)
└─> create UserAdmin:Issuer
with
userAdmin = 'UserAdmin'; issuer = 'Alice'Script
All contracts used in a Daml transaction must be visible to the submitter or more precisely the union of actAs and readAs parties. In your example it looks like the Issuer contract is only visible to userAdmin (probably they are the only signatory and there are no observers?) but you’re trying to use it in a submission which only has alice as the reading party.
There are two ways to fix this:
- Make
alicean observer on the contract by adding theissuerof theIssuertemplate as an observer. - Add the userAdmin as a
readAsparty so switch tosubmitMulti [alice] [userAdmin]. While this is convenient in tests, in a real system getting the authority from the userAdmin to let Alice see all of their contracts can be tricky.
Based on the information you shared 1 seems like the best option.
Thank you for the response. I am using the same exact code as shown and shared in the Episode 3 of Daml introductory training. Was wondering why I am looking at this error!!
@ktreply
Could you point me to the video and the source code you used? The reason I ask is that, as far as I can see, the code in Introduction to Daml video tutorial series available from this link and in the Github repo, which those series reference, uses deprecated but still supported “controller … can” syntax in choices, which implicitly adds choice controller as an observer on the template. Thus, if you use the templates code from the videos or from the referenced Github repo, you shouldn’t get the error in the Daml Script that you experienced. I would expect to see this error only if you updated the templates by replacing the deprecated “controller … can” syntax with the “choice …” syntax. And if that’s what you did, then, as @cocreature advised, the fix is to explicitly add the choice controller as an observer on the template (unless the controller is a signatory).
Does this make sense? Please, let me know if you need additional help.