Can I create placeholder contractids?
App Development3 posts192 views1 likesLast activity May 2023
GY
gyorgybalazsiOP
May 2023It 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
CO
cocreature
May 2023There 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 usecoerceContractIdto use that for other types.
If possible, 1 definitely is the cleaner solution so I would try to go for that.
GY
gyorgybalazsi
May 2023Thank you, Moritz, coerceContractId is perfect for my purpose.