It would be convenient to me to transform a data type containing a contractid field in two steps:
Step #1: use a pure function to transform all other fields and set a placeholder value for the contractid
Step #2: in the choice where I use the transformed data override the placeholder with a real contractid
There isn’t any way to create contract ids in Daml.
The two options you have are:
- Refactor your code such that you don’t need to work with actual contract ids, e.g., add a type parameter to your type and works with strings or whatever in your pure code and then replace it.
- If that is not an option you could use an already existing contract id either from an actual contract (e.g.
self
) or passed in as an argument to your choice (on the client side you could just use an arbitrary string that matches the format). In your Daml code you can use coerceContractId
to use that for other types.
If possible, 1 definitely is the cleaner solution so I would try to go for that.
1 Like
Thank you, Moritz, coerceContractId
is perfect for my purpose.