Locking a Daml Finance holding in Typescript
- Ianw1OP
Hi, I wish to lock a Daml Finance holding from my UI. One way to do this would be to create a choice on a service contract and call into that, but I would like to be able to do it directly from the UI in TypeScript if possible.
However I am struggling to get the
newLockersparameter correct. I want to do something like:await ledger.exercise(Base.Acquire, borrowedCid as string as ContractId, {newLockers: ???, context:“Lock”, lockType: LockType.Semaphore});
But how do I create the
newLockersvalue in Typescript? I can see it is type DA.Set.Types.Set and I have tried various approaches but not succeeded. I am probably missing something obvious so any pointers appreciated, TIA. - Johan_Sjodin
Hi @Ianw1,
Please have a look at the following related forum questions which I trust provide an answer to your question.
Johan
Is there a way to specify a Daml Set value directly using the generated TypeScript and Java code? Features & Bugs
By “directly” I mean without first creating a Map<T, Unit> or similar. So far I was only able to do this indirectly: TypeScript: let attributesMap : damlTypes.Map<BookAttribute, {}> = damlTypes.emptyMap(); let pages: BookAttribute = {tag: "Pages", value: "104"}; attributesMap = attributesMap.set(pages, {}); let authors: BookAttribute = {tag: "Authors", value: ["Lewis Carroll", "John Tenniel"]}; attributesMap = attributesMap.set(authors, {}); let title: BookAttribute = {tag: "Title", value:…
Hi Guys, I have a daml template that takes in an argument of type Set, the template looks like below. It’s the last field, observers template Asset with assetType : AssetType -- The asset owner owner : Party -- The amount of the asset amount : Decimal observers : Set Party When using the Daml/ react library, What javascript datastructure do I pass in? I’ve tried passing in an an array of partyId, eg [party], Not quite sure what I need to pass in. also tried to use th…
- Ianw1
Great, thank you @Johan_Sjodin. In case anyone else is looking for this in future here is my code:
var partiesMap : Map<Party, {}> = emptyMap(); partiesMap = partiesMap.set(party, {}) const partiesSet = {map: partiesMap} await ledger.exercise(Base.Acquire, borrowedCid as string as ContractId<Base>, {newLockers: partiesSet, context:"Lock", lockType: LockType.Semaphore}); - Stephen
Ianw1:borrowedCid as string as ContractId<Base>Assuming you’re doing this to convert from a template contract-ID to an interface contract-ID, I strongly recommend doing
Tpl.toInterface(Base, borrowedCid)instead whereTplis the template type ofborrowedCid(defined here); this is statically type-checked liketoInterfaceContractIdin Daml, so will fail to compile if the template doesn’t actually implement the interface.