Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/How to use `Any{Template,Choice,Key}`?Forum ↗

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

App Development2 posts223 views1 likesLast activity Jan 2022
LU
LucianoOP
Jan 2022

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.

CO
cocreature
Jan 2022

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.

← Back to Discussions