# Finance Library Interface Casting

**URL:** <https://forum.canton.network/t/finance-library-interface-casting/5828>\
**Category:** App Development\
**Tags:** daml-finance\
**Created:** [December 15, 2022, 12:19pm UTC](https://forum.canton.network/t/finance-library-interface-casting/5828 "2022-12-15T12:19:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![VictorShneer](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/victorshneer/32/5413_2.png) [@VictorShneer](https://forum.canton.network/u/VictorShneer)\
**Post date:** [December 15, 2022, 12:19pm UTC](https://forum.canton.network/t/finance-library-interface-casting/5828/1 "2022-12-15T12:19:51Z")

</div>

Hi Finance team!

I have a template that implements Fungible interface.  
In order to Merge or Split I need to work with `ContractId Fungible` type.  
Imagine that my input is `ContractId Holding.I` type.  
Is it right that in order to cast from `ContractId Holding.I` to `ContractId Fungible` I have to go through three steps. Like this:

```haskell
holdingCid = fromInterfaceContractId @Holding holdingIcid -- holdingIcid : Holding.I
fungibleIcid = toInterfaceContractId @Fungible.I holdingCid
fungibleCid = fromInterfaceContractId @Fungible fungibleIcid

```

I tested it in the Update context and it works. Is it the only way, or I missing something?  
I’m asking mostly for the sake of understanding. This is not a production code.

Thanks!

---

<div class="post-metadata">

**Author:** ![Matteo\_Limberto](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/matteo_limberto/32/2823_2.png) [@Matteo\_Limberto](https://forum.canton.network/u/Matteo_Limberto)\
**Post date:** [December 16, 2022, 8:09am UTC](https://forum.canton.network/t/finance-library-interface-casting/5828/2 "2022-12-16T08:09:53Z")

</div>

Hi @VictorShneer,

You can use the following casting functions.

- template cid → interface cid : `toInterfaceContractId`
- interface cid → template cid : `fromInterfaceContractId`
- interface cid → interface cid : `coerceInterfaceContractId` (or `coerceContractId` for an SDK version earlier than `2.5.0`

In your case, you can use the third option to convert a `ContractId Holding.I` to a `ContractId Fungible.I`

---

<div class="post-metadata">

**Author:** ![VictorShneer](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/victorshneer/32/5413_2.png) [@VictorShneer](https://forum.canton.network/u/VictorShneer)\
**Post date:** [December 16, 2022, 8:22am UTC](https://forum.canton.network/t/finance-library-interface-casting/5828/3 "2022-12-16T08:22:08Z")

</div>

> [@Matteo\_Limberto](#):
>
> coerceContractId

Cool thanks! Is it documented?

 ![Screenshot 2022-12-16 at 10.16.38](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/0/0e3a9e835bedc680367ff89887b3c6293566a7e0.png)  
 ![Screenshot 2022-12-16 at 10.17.24](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/b/b543aa69f48bb5179a2094692acd4d70db0ad26e.png)

---

<div class="post-metadata">

**Author:** ![Matteo\_Limberto](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/matteo_limberto/32/2823_2.png) [@Matteo\_Limberto](https://forum.canton.network/u/Matteo_Limberto)\
**Post date:** [December 16, 2022, 8:28am UTC](https://forum.canton.network/t/finance-library-interface-casting/5828/4 "2022-12-16T08:28:41Z")

</div>

`coerceInterfaceContractId` will be documented in the documentation for the `2.5.0` release.

`coerceContractId`, on the other hand, is not documented.
