Anoma Developer Documentation
  • Overview
  • Build
    • Getting Started
    • Your First Anoma App
      • Define a Resource
      • Write a Transaction Function
      • Write a Projection Function
      • Run your App
    • Anoma App Examples
  • LEARN
    • Overview
    • State Model
      • Model Comparison
    • Resource Machine
      • Information Flow Control
    • Resources
      • State
      • Logic
      • Kind
      • Lifecycle
    • Transactions
      • Delta
      • Actions
      • Balanced Transactions
      • Intents
    • Applications
      • Backend
      • Interface
    • Services
      • Indexing
      • Solving
Powered by GitBook
On this page
  1. Build
  2. Your First Anoma App

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.

~/HelloWorld/
touch GetMessage.juvix

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!".

GetMessage.juvix
module GetMessage;

import Stdlib.Prelude open;
import Applib open;

--- Extract the message from a HelloWorld ;Resource;
main (resource : Resource) : String :=
  resource |> Resource.label |> Label.toNat |> builtinAnomaDecode;

In the following chapter, we will compile and "deploy" our code locally.

PreviousWrite a Transaction FunctionNextRun your App

Last updated 27 days ago