Create Copy of Contract using Interface Reference

Hi All,

I have recently been exploring the Daml.Finance Library and familiarising myself with the Interface implementation.

I have created a contract with a reference to the Base Instrument.Key (like the holding does).

template Trade
  with
    instrument : Instrument.K

In one of my choices I would like to create another instrument using the instrument referenced in the contract.

I have tried the following

instrumentContract <- fetchInterfaceByKey @Instrument.R instrument
create instrumentContract with
   depository = otherParty

But am getting the following error

No instance for (DA.Internal.Record.HasField “depository” Instrument.Instrument Party) arising from a use of ‘setField’. How should I approach this?

Is there a way to solve this? As the fetchInterfaceByKey only retrieves the Interface of a contract implementation, will I be able to recreate any instrument implementation this way ?

Hi @benedict_chan ,

You should be able to use the function fromInterface (documented here) to convert from the interface into its template value.

Kind Regards,
Brian