Write a Projection Function
Let's enrich our HelloWorld application by adding functionality that allows us to read the label we have just created.
To achieve this, we add a special type of function, a projection function. You can think of it as a read function and you can find more details about it under Interface.
We're adding a new file to accomodate our projection function.
We can now specify GetMessage.juvix
. It will take a resource
parameter of type Resource
. As the name suggests, this is a resource object and we're able to access its individual parameters (which you can again find details about in Resources). To access the label, we just use Resource.label
, then transform the label type to a Nat
via Label.toNat
, and finally decode it via builtinAnomaDecode
. We now have our cleartext label, in this case "Hello World!".
In the following chapter, we will compile and "deploy" our code locally.
Last updated