NodeJS API DAML Bindings

72 Views Asked by At

we have the following DAML Contract:

data Something = Option A | Option B deriving(Show, Eq)

data Details = Details with id: Text name: Text state: Text

template Main with a: Party b: Party

c: Something
d: Details

I know we can do the following for 'a' and 'b' :

fields:{ a: daml.party(a), b: daml.party(b),} But how can I write for c and d?

1

There are 1 best solutions below

2
cocreature On

For d you can use daml.record, something like the following:

daml.record({
  id: daml.text("youridhere"),
  name: daml.text("yournamehere"),
  state: daml.text("yourstatehere")
})

For c there is an issue in your type definition. Constructors need to have different names whereas in your example they’re both called Option. You can fix this by renaming one or both, e.g.,

data Something = OptionA A | OptionB B deriving(Show, Eq)

To construct a value, you can then use daml.variant:

daml.variant("OptionA", yourahere)