# Usage examples of exerciseByKey - @daml/ledger

**URL:** <https://forum.canton.network/t/usage-examples-of-exercisebykey-daml-ledger/1040>\
**Category:** App Development\
**Tags:** daml, ledger-api\
**Created:** [August 13, 2020, 6:42pm UTC](https://forum.canton.network/t/usage-examples-of-exercisebykey-daml-ledger/1040 "2020-08-13T18:42:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex\_m](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/alex_m/32/550_2.png) [@alex\_m](https://forum.canton.network/u/alex_m)\
**Post date:** [August 13, 2020, 6:42pm UTC](https://forum.canton.network/t/usage-examples-of-exercisebykey-daml-ledger/1040/1 "2020-08-13T18:42:44Z")

</div>

Are there any usage examples of `exerciseByKey`? Can contract keys be easily constructed and used in something like this:

`ledger.exerciseByKey(Handover, { "_1": owner, "_2": id }, { newHandler: handler })`

…or do the JS contract keys have unattractive type signatures? (requiring you to hold on to a reference to the key, as opposed to constructing it when needed).

Thanks for the help,  
Alex

---

<div class="post-metadata">

**Author:** ![alex\_m](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/alex_m/32/550_2.png) [@alex\_m](https://forum.canton.network/u/alex_m)\
**Post date:** [August 13, 2020, 6:52pm UTC](https://forum.canton.network/t/usage-examples-of-exercisebykey-daml-ledger/1040/2 "2020-08-13T18:52:52Z")

</div>

Never mind, got it working with:  
`await ledger.exerciseByKey(Product.HandoverProduct, { _1: product.owner, _2: product.productId }, { newHandler: product.handler });`

---

<div class="post-metadata">

**Author:** ![Leonid\_Rozenberg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/leonid_rozenberg/32/48_2.png) [@Leonid\_Rozenberg](https://forum.canton.network/u/Leonid_Rozenberg)\
**Post date:** [August 13, 2020, 6:53pm UTC](https://forum.canton.network/t/usage-examples-of-exercisebykey-daml-ledger/1040/3 "2020-08-13T18:53:58Z")

</div>

@alex_m I was going to suggest looking at [this code in DAVL](https://github.com/digital-asset/davl/blob/00adfee384553caae8bb0b21520d88a2fca38b19/ui/src/features/employeeView/Requests.tsx#L66). Glad that you got it to work.

---

<div class="post-metadata">

**Author:** ![alex\_m](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/alex_m/32/550_2.png) [@alex\_m](https://forum.canton.network/u/alex_m)\
**Post date:** [August 13, 2020, 6:54pm UTC](https://forum.canton.network/t/usage-examples-of-exercisebykey-daml-ledger/1040/4 "2020-08-13T18:54:46Z")

</div>

Cheers! I’ll check it out anyway.
