# Use self-type in contract keys

**URL:** <https://forum.canton.network/t/use-self-type-in-contract-keys/2233>\
**Category:** App Development\
**Tags:** daml\
**Created:** [March 8, 2021, 10:57pm UTC](https://forum.canton.network/t/use-self-type-in-contract-keys/2233 "2021-03-08T22:57:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Kalcza](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/tamas_kalcza/32/1788_2.png) [@Tamas\_Kalcza](https://forum.canton.network/u/Tamas_Kalcza)\
**Post date:** [March 8, 2021, 10:57pm UTC](https://forum.canton.network/t/use-self-type-in-contract-keys/2233/1 "2021-03-08T22:57:00Z")

</div>

I know the following is technically possible. Are there any strange consequences, performance impacts maybe to use the template type in the contract key?

```haskell
template Example
  with
    owner : Party
    value : Int
  where
    signatory owner
    key this : Example
    maintainer key.owner

example_test : Script ()
example_test = do
  owner <- allocateParty "John Doe"
  let example = Example owner 42

  owner `submit` createCmd example

  Some (_, foundExample) <- queryContractKey @Example owner example

  example === foundExample

```

---

<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:** [March 9, 2021, 5:57am UTC](https://forum.canton.network/t/use-self-type-in-contract-keys/2233/2 "2021-03-09T05:57:01Z")

</div>

There shouldn’t be any technical issues with this. I guess you can argue it might be slightly confusing to mix up the key type and the template type but from a technical pov that doesn’t matter.

---

<div class="post-metadata">

**Author:** ![bernhard](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/bernhard/32/356_2.png) [@bernhard](https://forum.canton.network/u/bernhard)\
**Post date:** [March 9, 2021, 7:29am UTC](https://forum.canton.network/t/use-self-type-in-contract-keys/2233/3 "2021-03-09T07:29:55Z")

</div>

I do this quite frequently. It tends to make sense if you have hierarchical relationships between contracts. eg

```haskell
template Parent
  with
    p : Party
    id : Text
  where
    signatory p
    key this : Parent
    maintainer key.p

template Child
  with
    parent : Parent
    childId : Text
  where
    signatory parent.p
    key this : Child
    maintainer parent.p

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Kalcza](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/tamas_kalcza/32/1788_2.png) [@Tamas\_Kalcza](https://forum.canton.network/u/Tamas_Kalcza)\
**Post date:** [March 9, 2021, 7:56am UTC](https://forum.canton.network/t/use-self-type-in-contract-keys/2233/4 "2021-03-09T07:56:41Z")

</div>

Thanks, appreciate the answers. I think I have found a perfectly good use case for this. So, if it’s not considered some anti-pattern, I will go with this approach.

I use it for “marker contracts”. These contracts are quite simple and I wanted to prevent duplication of them. Using keys seemed like an easy solution.

For the key I have to use all properties of the template, and that’s why I started to think of reusing what I had already.
