How to use the Token Instrument packages

A Token is a simple instrument template whose economic terms on the ledger are defined by two textual fields, namely an id and a description.

It is often used to model financial instruments that do not exhibit complex lifecycling logic, such as currencies.

How to create a Token Instrument

The following code snippets are taken from the Getting Started tutorial, which you can install using the Daml assistant.

In order to instantiate a Token Instrument, we first need to create the corresponding instrument factory template

  tokenFactoryCid <- toInterfaceContractId @Token.F <$> submit bank do
    createCmd Token.Factory with
      provider = bank
      observers = empty

We can then specify the terms of the instrument and exercise the Create choice in the factory to create the token.

  let
    instrumentId = Id "USD"
    instrumentVersion = "0"
    instrumentKey = InstrumentKey with
      issuer = bank
      depository = bank
      id = instrumentId
      version = instrumentVersion
  now <- getTime

  submit bank do
    exerciseCmd tokenFactoryCid Token.Create with
      token = Token with
        instrument = instrumentKey
        description = "Instrument representing units of a generic token"
        validAsOf = now
      observers = empty

How to lifecycle a Token Instrument

Generic corporate actions, such as Distribution events, can be applied to Token Instruments. The Lifecycling section of the Getting Started tutorial shows how this is done in detail.