HoloWorld Tutorial: Sharing to the DHT

Before continuning with this tutorial, make sure that you've completed the last one, writing tests.

Now that we're authoring content to a local chain, of course we also want to know how to update our code so that it shares information using the Distributed Hash Table. The DHT is the "shared database" of a Holochain application. We have to make some tweaks to our HoloWorld code to make this work.

In our dna.json file, under Entries, we need to modify the behaviour of holoText type entries. Instead of just being stored in your local source chain, we'd like to share them to the DHT.

Change Sharing from private to public

This means that if entries successfully pass validateCommitand are written to the local source chain, they then trigger two other things to occur:

  1. attempting to add the entry to the DHT of the same node as authored the entry
  2. notifying other nodes running the same application to write the entry to their entry DHT as well

Before ANY node will actually write an entry into the DHT, it will first seek to validate it, according to the shared rules of the application. 

Holochain will call a function that we haven't yet defined in our code to perform this, validatePut. Holochain will throw an error if validatePutis not defined.

When an app attemps to write something to its local DHT, we call that a "put".

In readerWriter.js, add the following to your code, after validateCommit:

function validatePut() {
  return true

One further step to take. 

Because the entry is no longer just in our local source chain, in our holoTextRead function, we can try to retrieve it using getfrom the DHT.

// remove { Local: true } from
// var holoText = get(hash, { Local: true })
// to end up with
  var holoText = get(hash) 
That's it. Your tests will still work, but now your entry will be fetched from the DHT. 
With multiple nodes running, you would be able to retrieve the entries of others.
The next tutorial will cover how to add a user interface to the HoloWorld app, so that you can manually write and read entries!