HandCash data attachment to the Blockchain experiment

kelsola
3 min readMar 24, 2022

--

While developing my app, I’ve used the HandCash API to send payments from one user to another. This payment aspect of HandCash is incredible and I couldn’t say enough good things about it. But that’s a subject for another day. Today, I used HandCash for something different as I wanted to test out the data attachment capabilities that I keep hearing about. It seemed like the right time to get my feet wet in these uncharted waters. (Never a bad thing in web development, especially when it could lead to upgrades in the future.)

So, to give you a visual, I built a social media application where users post stuff. Like a Reddit. Or Twetch or Twitter.

With that visual in your brain, think about posts on those platforms and the data they contain. You know, the title, username, actual text, etc. That’s what I attached to the HandCash payment, which is the same data I send to my Mongo database after a user creates a post. (I sent it in json format, but you may also use hex or base64 format)

Here’s the only line of code I needed to add data to the blockchain:

attachment: { format: ‘json’, value: {“post”: post} }

Before sending it through, I added a console.log on my backend to see what it would look like. And unsurprisingly, it’s exactly how the HandCash documentation described.

attachments: [ { value: [Object], format: ‘json’ } ]

At this point, I didn’t really know what to do with that information, but the transaction ID was also included, so I went to https://whatsonchain.com and entered the TX ID. Here’s the link if you would like to see: https://whatsonchain.com/tx/d7c243b745c47dcc95ffde821971720e0a749859a32403c70b85c7d581b7e3b1

While skimming through whatsonchain, I noticed one distinct difference in the list of transactions. One item contained “OP_RETURN” instead of the usual long string of numbers and letters. So, I clicked on it, and there she was: My post data in all its digital glory. What a sight to behold.

So, that got me thinking. How could this be used over Mongo? Could I pull this Blockchain data from the transaction ID and display it on the page instead of having it come from Mongo? I then thought it would be possible if I added the TX ID to a URL (for the post) and pulled the data (from somewhere) via that URL, which I could then use to display the data on the page. I would have to replace my readable “slug” for an ugly long string though, and I wasn’t too keen on that idea. So my thought process went to thinking about how HandCash’s handle system or our web-based URL system flips that switch on its head, and how maybe there is some way to do it.

But I really don’t know. I am curious if, in reality, storing this type of data on-chain would be worthwhile and feasible. I remember reading that Twetch stores everything on-chain, but I don’t know if they also use an outside database. It’s hard to think they don’t, as keeping track of things that update constantly — like stats — seems hard to achieve outside of a constructed database. But then again, like I said, I’m new to this Blockchain + data thing.

But my gut tells me there is. There has to be. I mean, the BSV Blockchain has been billed as an upgrade to AWS and other cloud service providers. Companies like UNISOT are using it for their global supply chain business, and I’ve heard plenty about companies storing their data on it and how it can be used for these purposes. So, there has to be. Where there’s a will, there’s a way.

Luckily, I don’t need to worry about that aspect right now as I’m pretty happy with Mongo. The real data-storage use-case I’m interested in is something more static: Image uploads. I would happily add/upload user’s images to the Blockchain and retrieve it via that URL, over Google Cloud or AWS or Mongo (which I’ve learned I shouldn’t use for images).

Fortunately, because of a Joshua Henslee video, I know it can be done. Unfortunately, it wasn’t through HandCash, and based upon HandCash’s documentation, I don’t think image uploading is a possibility quite yet, so I’m not sure exactly how I should go about it. Do I do 2 transactions? 1 for payment, 1 for image uploads? I don’t know right now so I’ll think more about it later.

For now, I’m done blabbing my thoughts out and will ask you if you’d like to blab some of your own. Feel free to share any you might have.

Thanks for reading,

Sam

--

--

No responses yet