In this page, we're defining a resource object and giving it a custom label, "Hello World!".
Defining the Resource Object
Let's start by creating a new file that will contain our resource definition.
~/HelloWorld/
touch HelloWorld.juvix
Next, we preface our HelloWorld.juvix file with the standard module and imports.
HelloWorld.juvix
-- At the start of a Juvix file, we must declare a module with the filename.
module HelloWorld;
-- We import the standard library prelude as well as the Applib library.
import Stdlib.Prelude open;
import Applib open;
We now start defining our resource which we call mkHelloWorldResource by giving it values for logic, label, value, quantity, ephemeral, nonce, randSeed and nullifierKeyCommitment. You can find more detailed information on the resource and its parameters in Resources.
Let's start by putting default values for logic and value and pass the message parameter to label.
HelloWorld.juvix
-- ### Module, imports ###
--- A logic function that is always valid.
logic (publicInputs : Instance) (privateInputs : Witness) : Bool := true;
--- Creates a new ;Resource; that stores a ;String; message.
--- @param nonce A number used to ensure resource uniqueness
--- @param message The message to store in the ;Resource;.
mkHelloWorldResource
(nonce : Nat)
(message : String)
{ephemeral : Bool := false}
: Resource :=
mkResource@{
label := builtinAnomaEncode message;
logic;
value := 0;
};
In the context of our HelloWorld application, this implies that we're passing the "Hello World!" message when we're creating the resource. This allows us to set any string, like "Hello Anomages!". In addition to that we assign true to the logic, implying that this resource will not have any logic constraints. Similarly, we assign zero for value which is an arbitrary default.
assign default parameter 0 to nullifierKeyCommitment
These default values are artifacts of the current devnet implementation.
See the complete HelloWorld.juvix file.
HelloWorld.juvix
module HelloWorld;
import Stdlib.Prelude open;
import Applib open;
--- A logic function that is always valid.
logic (publicInputs : Instance) (privateInputs : Witness) : Bool := true;
--- Creates a new ;Resource; that stores a ;String; message.
--- @param nonce A number used to ensure resource uniqueness
--- @param message The message to store in the ;Resource;.
mkHelloWorldResource
(nonce : Nat)
(message : String)
{ephemeral : Bool := false}
: Resource :=
mkResource@{
label := builtinAnomaEncode message;
logic;
value := 0;
quantity := 1;
nonce;
ephemeral;
randSeed := 0;
nullifierKeyCommitment := 0;
};
Next, we're going to build the transaction function which will be used to initialize the resource object via transaction we manually prepare with our code.