How to use `Any{Template,Choice,Key}`?

These three data types are used to represent existential types, according to the docs.

My first thought would be to use it to reference a contract of unknown type e.g.

template Foo
  with
    bar : ContractId AnyTemplate
  ...

But this doesn’t work because it’s not serializable.

It’s not clear to me how these can be used in practice. Could you give an example?

If they’re not meant for general consumption, maybe we should -- | HIDE them in the docs.

It’s perfectly fine to use them just not in contexts where they need to be serializable.

They were originally added for triggers where a transaction contains a set of AnyTemplate to store the ACS which is a heterogeneous map so it cannot use a single template type.

I think you can often have similar usecases in your own code where you want to track a heterogeneous set or map and then those types come in handy in your own code as long as you don’t need to store it across transactions.

1 Like