HoloWorld Tutorial: Writing the application DNA

Make sure that you’ve completed the first HoloWorld tutorial step of creating a project folder.

For our simple “hello world” app, our goal will be very simple: to enable writing simple strings into our local source chain, and to then retrieve that data from the source chain. Note that because Holochain uses hash chain technology, and a distributed hash table (DHT) this does NOT work like a conventional SQL, NoSQL, or Graph database.

Open the project folder in a text editor of your choice. Programs such as Vim, Atom, Sublime Text, VS Code, which have syntax highlighting will be best. Then open the dna/dna.json file in your editor.

Notice that the application name has already been set, using the HoloWorld name that was used with the hcdev init command.

We could, however, update the Properties -> Description value to something relevant, for good practice.

Change the value to “the hello world app for Holochain”.

We can also remove configuration properties which we don’t need in our case. 

Remove the “BasedOn” property, used when an app needs to refer back to a different related application, by removing the following from the file:

"BasedOn": "",

Similarly, remove the “Progenitor” property, used to refer to an initial app publisher/creator.

"Progenitor": {
    "Identity": "",
    "PubKey": null
},

 

Zomes

Now, let’s configure the “Zomes”, the core functionality of our app. Notice that Zomes is an array (because of the square brackets []), meaning that we can define multiple if necessary.

The hcdev init command has prepopulated some values for reference. We have to modify these. 

First of all, let us change the name and details of the zome to something relevant to our application. We’ll rename the first and only Zome to something that describes our functionality.

Change the “Name” property to have a value of “readerWriter”.

Change the “Description” property to “read and write data”. 

Change the “CodeFile” property to “readerWriter.js”. This follows a convention of naming your CodeFile the same as your Zome name, which is recommended (but not enforced).

Because we changed those values, we also need to rename our actual Zome folder name, and the name of the file within it. Using whatever method you’d like, under the “dna” folder, rename the “sampleZome” folder to “readerWriter”, matching the Zome name we gave. Next, change the name of the “sampleZome.js” file in that folder to “readerWriter.js” matching the name given in “CodeFile”. 

 

Zome Entries

Next we can move on to providing a definition for the data that we would like to store in our application. This is done under the “Entries” property of the readerWriter Zome. “Entries” are what we call records written to the source chain or the DHT! Since the data apps may wish to store ranges from very simple to very complex, Holochain accommodates this. The data we wish to store doesn’t have multiple properties, but just one, so we can use a simple string, whereas the sampleZome defined a more complex JSON type. 

Change the “DataFormat” property of the Entry definition from “json” to “string”. 

Since we’ve done this, we do not need to point to a schema definition file. Remove the “Schema” and “SchemaFile” properties entirely! We should also clean up the now unnecessary “sampleEntry.json” file from the “readerWriter” folder by deleting it.

Next, we should give the Entry type a relevant name. The name is important, and should be descriptive. 

Change the “Name” property from “sampleEntry” to “holoText”.

At this stage, let’s assume that we would like to simply write this text to our local source chain, not to the DHT, and keep it private. Change the “Sharing” property from “public” to “private”.

That’s everything necessary for the Entries! 

 

Zome Functions

The last thing for configuring our application DNA is to specify the primary functions we wish to define. This is done under the “Functions” property of a Zome. A function MUST be added here in order to be callable by your testing suite, or a user interface, or any client. We have two basic functions we would like to enable, writing a “holoText” entry, and reading a “holoText” entry. So we will need just two function definitions. 

Delete the third function definition with the name “doSampleAction” by removing the 5 lines, plus the preceding comma, to keep valid JSON syntax. 

Now we can simply rename the two remaining functions, which already correspond nicely. 

Change the “Name” property of “sampleEntryCreate” to “holoTextWrite”.

Change the “Name” property of “sampleEntryRead” to “holoTextRead”.

For BOTH functions, simplify the “CallingType” property from “json” to “string”, since what is passed to these functions will be a simple string, and what is returned will also be one.

Because we don’t yet know exactly what we want the “Exposure” of these functions to be, for both functions, remove the property “Exposure”: “public” and the preceding comma.

That is the final step in configuring the DNA for our HoloWorld app! The following HoloWorld Tutorial articles will cover how to write the application code, how to validate the entries, how to test your application, and how to connect a UI.

Return to the DNA documentation page, or continue with the tutorial.