Finance Library Interface Casting
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:
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!
Hi @VictorShneer,
You can use the following casting functions.
- template cid → interface cid :
toInterfaceContractId - interface cid → template cid :
fromInterfaceContractId - interface cid → interface cid :
coerceInterfaceContractId(orcoerceContractIdfor an SDK version earlier than2.5.0
In your case, you can use the third option to convert a ContractId Holding.I to a ContractId Fungible.I
coerceInterfaceContractId will be documented in the documentation for the 2.5.0 release.
coerceContractId, on the other hand, is not documented.

