# Error when trying to exercise a choice with Dazl

**URL:** <https://forum.canton.network/t/error-when-trying-to-exercise-a-choice-with-dazl/5086>\
**Category:** App Development\
**Tags:** dazl\
**Created:** [August 16, 2022, 10:32am UTC](https://forum.canton.network/t/error-when-trying-to-exercise-a-choice-with-dazl/5086 "2022-08-16T10:32:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gyorgybalazsi](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gyorgybalazsi/32/684_2.png) [@gyorgybalazsi](https://forum.canton.network/u/gyorgybalazsi)\
**Post date:** [August 16, 2022, 10:32am UTC](https://forum.canton.network/t/error-when-trying-to-exercise-a-choice-with-dazl/5086/1 "2022-08-16T10:32:55Z")

</div>

I’m trying to exercise the “Give” choice on the “Asset” contract in the “skeleton” template with Dazl the following way:

```haskell
import asyncio
import dazl

alice = 'Alice::1220fe4924fd4168a3cd44765044ffc5424030a55b0589506f03be6f80dadc57ead2'
bob = 'Bob::1220fe4924fd4168a3cd44765044ffc5424030a55b0589506f03be6f80dadc57ead2'
hello_id = '006aa1e9d9fdfc83280ca7dd94e184cac73b184e561f09b6e36a5cd9a7e1114e21ca00122005efd1caca5354c4bf6cf755e1354952b39f95b0fedf6f63267d42a65f1a5b15'

async def main():
    async with dazl.connect(url='http://localhost:6865', act_as=alice) as client:
        await client.exercise(dazl.prim.contracts.ContractId(hello_id), "Give", {"newOwner": bob})

# Python 3.7+
asyncio.run(main())

```

I get the following error:

```haskell
gyorgybalazsi@BGY dazl % python3 give.py
Traceback (most recent call last):
  File "/Users/gyorgybalazsi/_dobdel/dazl_test/dazl/give.py", line 13, in <module>
    asyncio.run(main())
  File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/Users/gyorgybalazsi/_dobdel/dazl_test/dazl/give.py", line 10, in main
    await client.exercise(dazl.prim.contracts.ContractId(hello_id), "Main:Give", {"newOwner": bob})
TypeError: __init__ () missing 1 required positional argument: 'value'

```

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [August 16, 2022, 10:44am UTC](https://forum.canton.network/t/error-when-trying-to-exercise-a-choice-with-dazl/5086/2 "2022-08-16T10:44:39Z")

</div>

[`ContractId`](https://github.com/digital-asset/dazl-client/blob/6ce8c1728999c414cee57bb909fa6e0631f84ff9/python/dazl/prim/contracts.py#L24) takes two arguments: The `value_type` meaning the template and the `value` meaning the actual contract id.

You’re only passing the latter, try something like `ContractId("$yourpkgidhere:$modulename:Asset", hello_id)`.

---

<div class="post-metadata">

**Author:** ![gyorgybalazsi](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gyorgybalazsi/32/684_2.png) [@gyorgybalazsi](https://forum.canton.network/u/gyorgybalazsi)\
**Post date:** [August 16, 2022, 11:12am UTC](https://forum.canton.network/t/error-when-trying-to-exercise-a-choice-with-dazl/5086/3 "2022-08-16T11:12:21Z")

</div>

Thanks, we are closer but not quite there. I’m trying:

```haskell
import asyncio
import dazl
from dazl.damlast.daml_lf_1 import TypeConName

alice = 'Alice::1220fe4924fd4168a3cd44765044ffc5424030a55b0589506f03be6f80dadc57ead2'
bob = 'Bob::1220fe4924fd4168a3cd44765044ffc5424030a55b0589506f03be6f80dadc57ead2'
hello_type = '205cce0e86fa0481dabe9e64d6481b47806276db206527b8211bb072fba41458:Main:Asset'
hello_id = '006aa1e9d9fdfc83280ca7dd94e184cac73b184e561f09b6e36a5cd9a7e1114e21ca00122005efd1caca5354c4bf6cf755e1354952b39f95b0fedf6f63267d42a65f1a5b15'

async def main():
    async with dazl.connect(url='http://localhost:6865', act_as=alice) as client:
        await client.exercise(dazl.prim.contracts.ContractId(hello_type,hello_id), "Give", {"newOwner": bob})

# Python 3.7+
asyncio.run(main())

```

The error is:

```haskell
raise ValueError("value_type must be a TypeConName")
ValueError: value_type must be a TypeConName

```

I can see `TypeConName` in the code you’ve linked, it seems I need to dig deeper.

---

<div class="post-metadata">

**Author:** ![gyorgybalazsi](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gyorgybalazsi/32/684_2.png) [@gyorgybalazsi](https://forum.canton.network/u/gyorgybalazsi)\
**Post date:** [August 16, 2022, 11:30am UTC](https://forum.canton.network/t/error-when-trying-to-exercise-a-choice-with-dazl/5086/4 "2022-08-16T11:30:31Z")

</div>

It’s strange that when I print the ` __repr__ ()` for the contract id, I get the following, where the value\_type is not within quotation marks, otherwise it’s identical with what you suggested:

```haskell
ContractId(205cce0e86fa0481dabe9e64d6481b47806276db206527b8211bb072fba41458:Main:Asset, '00dc41ee7d8bb4a5ecc1fa8e5dbf46cfe8b9482e06d0929e1b924ad9650e43419eca0012204304731dc090cb18d497e41feb49b39273019927c41679f38e2dbad6cfcd6e0f')

```

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [August 16, 2022, 11:57am UTC](https://forum.canton.network/t/error-when-trying-to-exercise-a-choice-with-dazl/5086/5 "2022-08-16T11:57:35Z")

</div>

Apologies you need to throw `parse_type_con_name` around it, see [dazl-client/test\_command\_builder.py at 6ce8c1728999c414cee57bb909fa6e0631f84ff9 · digital-asset/dazl-client · GitHub](https://github.com/digital-asset/dazl-client/blob/6ce8c1728999c414cee57bb909fa6e0631f84ff9/python/tests/unit/test_command_builder.py#L15).

---

<div class="post-metadata">

**Author:** ![gyorgybalazsi](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gyorgybalazsi/32/684_2.png) [@gyorgybalazsi](https://forum.canton.network/u/gyorgybalazsi)\
**Post date:** [August 16, 2022, 12:36pm UTC](https://forum.canton.network/t/error-when-trying-to-exercise-a-choice-with-dazl/5086/6 "2022-08-16T12:36:18Z")

</div>

Thank you!

I record for posterity that this is the working version:

```haskell
import asyncio
import dazl
from dazl.damlast.lookup import parse_type_con_name
from dazl.prim.contracts import ContractId

alice = 'Alice::1220fe4924fd4168a3cd44765044ffc5424030a55b0589506f03be6f80dadc57ead2'
bob = 'Bob::1220fe4924fd4168a3cd44765044ffc5424030a55b0589506f03be6f80dadc57ead2'
hello_type = parse_type_con_name('205cce0e86fa0481dabe9e64d6481b47806276db206527b8211bb072fba41458:Main:Asset')
hello_id = '00f8e3b6345b44f612611dd2bde9902dec66ced2cb8a81e63192578420718a0ff4ca00122014669a9a4c4eb0058337a8443521c2cb71903159e9e7e7b9b4c9ad73258fb6c0'

async def main():
    async with dazl.connect(url='http://localhost:6865', act_as=alice) as client:
        await client.exercise(ContractId(hello_type, hello_id), "Give", {"newOwner": bob})

# Python 3.7+
asyncio.run(main())

```
