Skip to content
CCPEDIAby Unity Nodes
App Development

Cannot run dazl introductury example

3 posts369 views1 likesLast activity Nov 2021

  1. gyorgybalazsiOP

    I’d like to run the following introductory example from the dazl documentation:

    import asyncio
    import dazl
    
    async def main():
       async with dazl.connect(url='localhost:6865', read_as='Alice') as conn:
          async for event in conn.creates():
             print(event.contract_id, event.payload)
    
    # Python 3.7+ or later
    asyncio.run(main())
    

    See dazl.ledger

    On ‘localhost:6865’ a sandbox is running.

    I get the following error message:

    line 6, in main
        async for event in conn.creates():
    AttributeError: 'Connection' object has no attribute 'creates'
    

    What am I doing wring?

  2. dtanabe 1

    My apologies: the docs are incorrect.

    The correct version is this:

    import asyncio
    import dazl
    
    async def main():
       async with dazl.connect(url='localhost:6865', read_as='Alice') as conn:
          async with conn.query('*') as stream:
             async for event in stream.creates():
                print(event.contract_id, event.payload)
    
    # Python 3.7+ or later
    asyncio.run(main())
    

    We’ll update the docs as well. Thanks for bringing this to our attention!

  3. gyorgybalazsi

    Perfect, thank you!