# Update of Contract information

**URL:** <https://forum.canton.network/t/update-of-contract-information/621>\
**Category:** App Development\
**Tags:** daml\
**Created:** [June 9, 2020, 7:48pm UTC](https://forum.canton.network/t/update-of-contract-information/621 "2020-06-09T19:48:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bartcant](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/bartcant/32/823_2.png) [@bartcant](https://forum.canton.network/u/bartcant)\
**Post date:** [June 9, 2020, 7:48pm UTC](https://forum.canton.network/t/update-of-contract-information/621/1 "2020-06-09T19:48:58Z")

</div>

I am experimenting with DAML and wanted to write a module that saves and updates the details of a “Citizen” called CitizenInfo. I also added a Key = CitizenKey

I have the following DAML code

> ```
> module Registration where
> data CitizenInfo = CitizenInfo with
> citizendetail1 : Text
> citizendetail2 : Text
> citizendetail3 : Text
> deriving (Eq, Show)
> 
> data CitizenKey = CitizenKey with
> citizen : Party
> id : Text
> deriving (Eq, Show)
> 
> template CitizenRegistration
> with
> registrationCid : CitizenKey
> registrationData : CitizenInfo
> 
> where
> signatory registrationCid.citizen
> key registrationCid : CitizenKey
> maintainer key.citizen
> controller registrationCid.citizen can 
> nonconsuming Register : ContractId CitizenRegistration with
> newRegistrationCid : CitizenKey
> newRegistrationData : CitizenInfo
> do
> create CitizenRegistration with
> registrationCid = newRegistrationCid
> registrationData = newRegistrationData
> 
> nonconsuming UpdateRegistration : ContractId CitizenRegistration
> with
> newCitizenDetails : CitizenInfo
> do
> (oldRegistrationCid, oldRegistrationData) <- fetchByKey @CitizenRegistration (key this)
> archive oldRegistrationCid
> create CitizenRegistration with 
> registrationCid = oldRegistrationCid  
> registrationData = newCitizenDetails
> 
> ```

It currently gives me the following error message at the 2nd last line

> ```
> Couldn't match expected type ‘CitizenKey’
> with actual type ‘ContractId CitizenRegistration’
> • In the ‘registrationCid’ field of a record
> In the first argument of ‘create’, namely
> ‘CitizenRegistration
> {registrationCid = oldRegistrationCid,
> registrationData = newCitizenDetails}’
> In a stmt of a 'do' block:
> create
> CitizenRegistration
> {registrationCid = oldRegistrationCid,
> registrationData = newCitizenDetails}type
> 
> ```

Also I want to write a scenario for the ` UpdateRegistration,` so any insights are welcome

---

<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:** [June 9, 2020, 7:54pm UTC](https://forum.canton.network/t/update-of-contract-information/621/2 "2020-06-09T19:54:58Z")

</div>

You are mixing up contract ids and the data associated with the contract with the given id. `registrationCid` does not in fact store a contract id. It stores a contract key. So you also need to pass in the contract key not the contract id. Given the data of a template (here `oldRegistrationData`) you can always use the `key` function to get the contract key, So to fix your example you can use

```haskell
create CitizenRegistration with 
           registrationCid = key oldRegistrationData
           registrationData = newCitizenDetails

```

---

<div class="post-metadata">

**Author:** ![bartcant](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/bartcant/32/823_2.png) [@bartcant](https://forum.canton.network/u/bartcant)\
**Post date:** [June 9, 2020, 8:05pm UTC](https://forum.canton.network/t/update-of-contract-information/621/3 "2020-06-09T20:05:45Z")

</div>

Thanks for the explanation.

---

<div class="post-metadata">

**Author:** ![anthony](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/anthony/32/419_2.png) [@anthony](https://forum.canton.network/u/anthony)\
**Post date:** [June 12, 2020, 12:46pm UTC](https://forum.canton.network/t/update-of-contract-information/621/4 "2020-06-12T12:46:48Z")

</div>

Split this topic on June 12, 2020, 12:46pm UTC

3 posts were split to a new topic: [Last statement in a do block must be an expression?](https://forum.canton.network/t/last-statement-in-a-do-block-must-be-an-expression/638)

---

<div class="post-metadata">

**Author:** ![anthony](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/anthony/32/419_2.png) [@anthony](https://forum.canton.network/u/anthony)\
**Post date:** [June 12, 2020, 12:48pm UTC](https://forum.canton.network/t/update-of-contract-information/621/7 "2020-06-12T12:48:49Z")

</div>

Split this topic on June 12, 2020, 12:48pm UTC

4 posts were split to a new topic: [Couldn’t match type ‘Update’ with ‘(-\>) c0’](https://forum.canton.network/t/couldnt-match-type-update-with-c0/639)

---

<div class="post-metadata">

**Author:** ![anthony](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/anthony/32/419_2.png) [@anthony](https://forum.canton.network/u/anthony)\
**Post date:** [June 12, 2020, 12:49pm UTC](https://forum.canton.network/t/update-of-contract-information/621/11 "2020-06-12T12:49:47Z")

</div>

Split this topic on June 12, 2020, 12:49pm UTC

3 posts were split to a new topic: [Conflicting definitions for ‘alias’](https://forum.canton.network/t/conflicting-definitions-for-alias/640)
