Error when trying to exercise a choice with Dazl

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

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:

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?

ContractId 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).

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

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:

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.

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:

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

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.

1 Like

Thank you!

I record for posterity that this is the working version:

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())
1 Like