Difference between interface keys and contract keys? Why do we need interface keys?

Hi @code_monkey,

Thanks for your question. Let me try to clarify why we use the Reference workaround. I assume here that you are familiar with contract keys (which apply to templates and are documented here).

In Daml Finance we work with interfaces and, as Stephen mentions, Account is in this case an interface type, for which in principle multiple template implementations can exist.

We wanted a way to reference an Account by key, but interface keys are not currently supported: for interfaces we can only use ContractIds.

Hence the following workaround:

  • define a concrete template called Reference which is keyed (with a contract key)
  • have Reference store the ContractId of an Account

We then define some helper functions called exerciseInterfaceByKey which effectively

  • fetch the Reference contract by key
  • exercise a choice on the corresponding Account contract using the ContractId that is stored in the Reference

Hopefully we will be able to remove this workaround once interface keys are supported.

Matteo

2 Likes