Finance Library Interface Casting
- VictorShneerOP 1
Hi Finance team!
I have a template that implements Fungible interface.
In order to Merge or Split I need to work withContractId Fungibletype.
Imagine that my input isContractId Holding.Itype.
Is it right that in order to cast fromContractId Holding.ItoContractId FungibleI have to go through three steps. Like this:holdingCid = fromInterfaceContractId @Holding holdingIcid -- holdingIcid : Holding.I fungibleIcid = toInterfaceContractId @Fungible.I holdingCid fungibleCid = fromInterfaceContractId @Fungible fungibleIcidI 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!
- Matteo_Limberto 2
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.Ito aContractId Fungible.I - template cid → interface cid :
- VictorShneer
- Matteo_Limberto
coerceInterfaceContractIdwill be documented in the documentation for the2.5.0release.coerceContractId, on the other hand, is not documented.

