# Canton Console how to represent ENUM

**URL:** <https://forum.canton.network/t/canton-console-how-to-represent-enum/4502>\
**Category:** App Development\
**Tags:** canton\
**Created:** [May 10, 2022, 4:58am UTC](https://forum.canton.network/t/canton-console-how-to-represent-enum/4502 "2022-05-10T04:58:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dorrit\_Du](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/dorrit_du/32/2417_2.png) [@Dorrit\_Du](https://forum.canton.network/u/Dorrit_Du)\
**Post date:** [May 10, 2022, 4:58am UTC](https://forum.canton.network/t/canton-console-how-to-represent-enum/4502/1 "2022-05-10T04:58:14Z")

</div>

Hi Team,

Similar to the questions that I raised last week from [here](https://discuss.daml.com/t/canton-console-how-to-represent-da-set-da-map/4476) .

Now, we are adding the complexity to the template as shown below (with partyType with Enum type)

```haskell
data PartyType = Delegates | Entity deriving (Eq, Show)

template PartyInfo3
  with
    operator : Party -- party onboarding --
    referenceId : Map.Map Text Text
    partyType : PartyType
  where
    signatory operator

```

Looking at the sample contract from return, I understand that Enum is required but still puzzle to construct enumId & constructor part.

```haskell
 label = "partyType",
              value = Some(
                value = Value(
                  sum = Enum(
                    value = Enum(
                      enumId = Some(value = Identifier(packageId = "fb64fe96f2f08c34e344864507e65b0aeb779e9c808f21e21dbb13059a9ebc02", moduleName = "PartyInfo", entityName = "PartyType")),
                      constructor = "Delegates"

```

Can you please help giving the example? thanks in advanced

Cheers,  
Dorrit

---

<div class="post-metadata">

**Author:** ![Phoebe\_Nichols](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/phoebe_nichols/32/454_2.png) [@Phoebe\_Nichols](https://forum.canton.network/u/Phoebe_Nichols)\
**Post date:** [May 10, 2022, 9:28pm UTC](https://forum.canton.network/t/canton-console-how-to-represent-enum/4502/2 "2022-05-10T21:28:20Z")

</div>

Hi Dorrit,

You can instantiate the enum `PartyType` like this:

```haskell
22:05:24 ~/repos/canton-1/enterprise/app/target/release/canton-enterprise-2.3.0-SNA
PSHOT [enum]
🌸 ./bin/canton -c examples/01-simple-topology/simple-topology.conf
   _____ _
  / ____ | | |
 | | ___ ___ | |_ ______
 | | / _` | '_ \| __/ _ \| '_ \
 | |___| (_| | | | | || (_) | | | |
  \ _____\__ ,_|_| |_|\ __\___ /|_| |_|

  Welcome to Canton!
  Type `help` to get started. `exit` to leave.

@ import com.digitalasset.canton.examples.PhoTest.PartyInfo3
import com.digitalasset.canton.examples.PhoTest.PartyInfo3

@ import com.digitalasset.canton.examples.PhoTest.PartyType.Delegates
import com.digitalasset.canton.examples.PhoTest.PartyType.Delegates

@ import com.digitalasset.canton.examples.PhoTest.PartyType.Entity
import com.digitalasset.canton.examples.PhoTest.PartyType.Entity

@ import com.daml.ledger.client.binding.Primitive.GenMap
import com.daml.ledger.client.binding.Primitive.GenMap

@ import com.daml.ledger.client.binding.Primitive.Text
import com.daml.ledger.client.binding.Primitive.Text

@ 
val partyInfo3 = PartyInfo3(operator = operator.toPrim, referenceId = Map.empty[Tex
t,Text], partyType = Delegates)
partyInfo3: PartyInfo3 = PartyInfo3(
  operator = "operator::1220a01c682ce1d460746ec7175cac1d56effcea97060a8383d6abde2b9
c186baefd",
  referenceId = Map(),
  partyType = Delegates
)

@
val partyInfo3Again = PartyInfo3(operator = operator.toPrim, referenceId = Map.empty[Tex
t,Text], partyType = Entity)
partyInfo3: PartyInfo3 = PartyInfo3(
  operator = "operator::1220a01c682ce1d460746ec7175cac1d56effcea97060a8383d6abde2b9
c186baefd",
  referenceId = Map(),
  partyType = Entity
)

```

After this point you can do `val create = partyInfo3.create.command` etc to create the contract.

Does that answer your question?

Phoebe 😄

---

<div class="post-metadata">

**Author:** ![Dorrit\_Du](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/dorrit_du/32/2417_2.png) [@Dorrit\_Du](https://forum.canton.network/u/Dorrit_Du)\
**Post date:** [May 11, 2022, 12:52am UTC](https://forum.canton.network/t/canton-console-how-to-represent-enum/4502/3 "2022-05-11T00:52:12Z")

</div>

Thanks Phoebe, is there a way that we don’t use binding library? Because client doesn’t want to use codegen?

---

<div class="post-metadata">

**Author:** ![Phoebe\_Nichols](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/phoebe_nichols/32/454_2.png) [@Phoebe\_Nichols](https://forum.canton.network/u/Phoebe_Nichols)\
**Post date:** [May 11, 2022, 9:21am UTC](https://forum.canton.network/t/canton-console-how-to-represent-enum/4502/4 "2022-05-11T09:21:42Z")

</div>

Hi Dorrit,

You can do this without the binding library, yep. The important bit is

```haskell
val createCmd = ledger_api_utils.create(pkgIdStr,"PhoTest","PartyInfo3",Map("operat
or" -> operator,"referenceId" -> Value.Sum.GenMap(GenMap.of(Seq.empty)),"partyType"
 -> Value.Sum.Enum(Enum(constructor = "Delegates"))))

```

Here is all the operations that make this work

```haskell
🌸 ./bin/canton -c examples/01-simple-topology/simple-topology.conf
   _____ _
  / ____ | | |
 | | ___ ___ | |_ ______
 | | / _` | '_ \| __/ _ \| '_ \
 | |___| (_| | | | | || (_) | | | |
  \ _____\__ ,_|_| |_|\ __\___ /|_| |_|

  Welcome to Canton!
  Type `help` to get started. `exit` to leave.

@
val pkgIdStr = "cee0a65ec62d682a2025935a28810dac8ad722ec3ff5593ed646eaf88ad8cc9f"
pkgIdStr: String = "cee0a65ec62d682a2025935a28810dac8ad722ec3ff5593ed646eaf88ad8cc9
f"

@ val operator = participant1.parties.enable("operator")
operator: PartyId = operator::12202818444d...

@ participant1.dars.upload("dars/CantonExamples.dar")
res7: String = "12201cc2b4b2d2cce61fb8ce2274c34f9aa0611457c510b0d09071c8ea4a8a09fd8
f"

@ import com.daml.ledger.api.v1.value.GenMap
import com.daml.ledger.api.v1.value.GenMap

@ import com.daml.ledger.api.v1.value.Value
import com.daml.ledger.api.v1.value.Value

@ import com.daml.ledger.api.v1.value.Enum
import com.daml.ledger.api.v1.value.Enum

@ participant1.domains.connect_local(mydomain)

@
val createCmd = ledger_api_utils.create(pkgIdStr,"PhoTest","PartyInfo3",Map("operat
or" -> operator,"referenceId" -> Value.Sum.GenMap(GenMap.of(Seq.empty)),"partyType"
 -> Value.Sum.Enum(Enum(constructor = "Delegates"))))
createCmd: com.daml.ledger.api.v1.commands.Command = Command(
  command = Create(
    value = CreateCommand(
      templateId = Some(
        value = Identifier(
          packageId = "cee0a65ec62d682a2025935a28810dac8ad722ec3ff5593ed646eaf88ad8cc9f"
... <<some more stuff>>>...
            RecordField(
              label = "partyType",
              value = Some(
                value = Value(
                  sum = Enum(
                    value = Enum(enumId = None, constructor = "Delegates")
                  )
...

@ participant1.ledger_api.commands.submit(Seq(operator), Seq(createCmd))
res31: com.daml.ledger.api.v1.transaction.TransactionTree = TransactionTree(
  transactionId = "122067e87bd5bfaf00ba8c7be021836738fcb3cd8d0173718bb3d1c638b80821
0a7d",
  commandId = "32d1b35f-4038-4129-bd71-692205617274",
  workflowId = "",
  effectiveAt = Some(
    value = Timestamp(
    ...

```

Does that work for you?

Phoebe

---

<div class="post-metadata">

**Author:** ![Dorrit\_Du](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/dorrit_du/32/2417_2.png) [@Dorrit\_Du](https://forum.canton.network/u/Dorrit_Du)\
**Post date:** [May 13, 2022, 12:39am UTC](https://forum.canton.network/t/canton-console-how-to-represent-enum/4502/5 "2022-05-13T00:39:23Z")

</div>

@Phoebe_Nichols Work perfectly! thanks for your help
