1

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?

Alex
  • 11
  • 1

1 Answers1

1

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)
cocreature
  • 801
  • 5
  • 5
  • ---------------------JS CODE------------------------------ alex: daml.party(alex) bob: daml.party(bob) purchase: daml.record( {name: daml.text(name), id: daml.text(id), info: daml.party(info) }) status: daml.variant('A', daml.text('A'), 'B', daml.text('B)) -----------------QUESTION------------------------------------- I get the following error upon running node ./file.js Reference error: "name" is not defined. "name" is party of the Details so have i written in correctly in my node.js code ? – Alex Apr 01 '21 at 13:55
  • `name: daml.text(name)` you have to actually specify which name you want to use, e.g., `name: daml.text("Alice")` – cocreature Apr 01 '21 at 17:09