How do I get started learning the API? Basic voting application?

Hey everyone,

I’ve started to learn about SAFE very recently and am excited about the technology.
However, I’m struggling to get started actually developing a basic application and understanding the Web API.
I followed the tutorial about the Web App Quick Start and that works great. I also started to play around with the Web API Playground that is included in the repo.

I watched many videos on the MaidSafe YouTube channel, read everything about the project on the website, and looked through the forums a lot, but am still struggling to grasp how this actually works. There aren’t any real explanations to the methods in the documentation and don’t help me much as a beginner. The same goes for the Web API Playground that I mentioned before. I also can’t seem to find out if there’s any way to print out the actual contents of the objects on the right side. Is that possible?

My idea is to build a simple polling/voting web application for a start, but I simply can’t figure out how I would go about doing that. The introductory tutorial is great, but leaves much to be desired. It explains Mutable and Immutable data briefly, and mentions that every time the application is reloaded, the data is lost because it is written to a random location.

My question is then, how do I store data in a specific place and can retrieve it again when the application reloads? Is it possible to “bind” data to this specific application so every time anyone loads the application, they can read everything that was ever stored for it? Or can I make this data only accessible to the user itself, or partially public and partially private?

As you can see, I’m quite confused about this :smiley:

I also found this forum post about vote counters and that seems like a reasonable start for voting applications. That doesn’t mean I know how to implement something like that though.

I’m sorry if I sound like a complete idiot, I just don’t know how to get started digesting this whole thing and am wondering if SAFE would even be a good choice for a voting/election application, as I would like to do such a project for an upcoming semester in my university. From what I understood from the PARSEC video, this network would be ideal for a secure voting application because it is immune to traditional attacks like DDoS and man-in-the-middle. I first looked at blockchain technology due to it’s properties of making sure that no votes can be changed and a vote would be secure, but then realized the many downsides that would come with an implementation with a blockchain.

Am I completely misunderstanding this project and how it works, or am I just too dumb to understand it? Really any advice and push in the right direction would be highly appreciated for a noob like me. Thank you! :slightly_smiling_face:

5 Likes

I felt very much in the same boat when I tried to make an app. After looking at source of other people’s apps I just copied what they were doing, which was writing to an entry in one of the user’s containers. In my case it was a user’s private data.

There are new data types beyond mutable and immutable coming now, one of which is appendable data. Maybe for voting you could have an appendable data that is writable by desired users that they could append their vote to? The location of that object could be hard coded in your app.

3 Likes

Thank you for your answer! Do you have any recommendations on what apps would be simple to understand and learn from?

That sounds great! Is there a planned release date for it?

You might find reading the source code in SafenetworkJS helps, you will see high level functions there and can follow what they do.

Start with safenetwork-api.js

That file contains high level and supporting functions to do most common operations.

And please don’t think you are stupid. You are correct that the documentation needs more work, but you can learn this. Just ask questions, have a go, post bits of code you are struggling with etc. It can seem a lot to learn, but well worth it IMO. Also search this forum because others have asked and had help here before - you will see I ask a lot of questions here!

Good luck. I’m very interested to see how your app develops.

3 Likes

Thank you! I haven’t thought of doing that yet, I will definitely give it a go.

1 Like

Hey there, nice to see that you’re looking to build something!
Don’t feel stupid, things are a bit complicated in the beginning, much because it’s an early phase and there’s much change going on. Things are going to be much simpler eventually, in the meantime there are some hurdles but it’s always the most daunting in the beginning.

Polling and voting web app is a perfectly viable functionality to implement.

All of this is possible. I’m sorry I’m just in after an evening at the new neighbors, so I’m not going to attempt to explain it all just now. But for sure, what you want to do can be done.

And don’t be sorry and you don’t sound like a complete idiot - on the contrary. And also, anyone asking questions will come out ahead eventually :wink:

Let me get back when I’ve had some sleep :slight_smile:

4 Likes

Hey again :slight_smile:

You are arriving right in the middle of changes. So the post you are linking to, works with data types that have changed a bit since, and the data types that are available in all released bindings have just now been deprecated in favor of the new data types.

So, to give you something to play with right now, we would have to look at the deprecated types. But that won’t be very useful later. If you can stand to just build in theory for a short while, until the new data types are available in the bindings, then we can instead look at that.

I’d recommend to look at the new data types, better just get started with what will be used.
You can read the RFCs here:

If you want everyone to load the same public data, then it could be hard coded in the app for example, as mentioned here already. That would be the simplest thing to get started.
You can also use some deterministic hashing if you want a wide range of data addresses, that are not defined at design time. So the data is in specific places, but you don’t need to create them ahead of time.

For the voting, the use of an AD (append only data) as suggested here previously, seems perfect.
You could do a lot with a single instance. Simplest case I guess, is that all info is hard coded in your site, and then there’s input for the poll options, and at submit it’s appended.

It’s susceptible to spam, but that’s probably not an issue here.

When you read more about the new data types you might have some more ideas for the voting app, but please don’t hesitate to ask for advice on how to actually implement the functionality. I haven’t yet started working with the new data types, so it’s very interesting to toss these ideas. I think it’s a good thing to do also in the design process, even though we are a little bit late to actually influence the data types now. It’s not impossible but it’s fairly cemented now for a while as the RFCs closed and it’s full steam on to release.


Accessible to only the user itself is basic functionality. So you can create both published and unpublished data, where the latter is subdivided in private and shared data (shared is accessible by others that you choose to share it with, and you can set read/write/append permissions for them). Published is published forever so you can’t turn that clock. Private can be turned to published as well as shared. Shared can be turned to published.

When talking about partially public/private data, you’re looking for partially published or shared and private I think. This is something you’d arrange by combining published, shared and private. They will be distinct data type instances, but at UI level it can then be exposed as partially public and private data.
Do you have a more concrete vision of what you want to do with partially public / private?

So, right now the alternatives looks like this:

Unpublished

  • Private
    – Encrypted
    – Plain text
  • Shared
    – Encrypted
    – Plain text

Published

– Encrypted
– Plain text

What it means is that you can have a published data structure, that has encrypted entries. And so the content isn’t available to others unless they have the encryption key. This is still considered published because what ever you have there is open and accessible to everyone perpetually (albeit in an encrypted form if you so choose).

When you have an Unpublished data structure, the data is on the contrary not open and accessible to everyone. Specifically true for the Private flavor, which can only be accessed by the owner. It’s blocked on network level for anyone else. Shared is, as it sounds, shared with others - a closed group.
But also here you can have encrypted and not encrypted (i.e. plain text) content, and if encrypting the contents of Shared data, the encryption key needs to be shared as well, for the actual content to be meaningful.

Now, the big difference between Published and Unpublished, is the mutability.
The idea is that Published data must remain unchanged (it’s a basic principle of the network), while with Unpublished you are allowed to do changes.

All of this info is well explained in the RFCs so look at that and you’ll have a lot of material for new questions :slight_smile:

2 Likes

Most of the new data types are the same for most operations, and the API may be similar with some tweaks.

At this point it’s hard to understand the new types and particularly how the API will change, so I don’t think it’s a good place to start - no documentation (I don’t understand the RFCs well enough to design with them) and no example code. So I wouldn’t recommend that route. I think what you can learn from the existing APIs will transfer fairly easily when the new APIs come along though.

Thank you both for the very detailed and helpful answers, I really appreciate it.

Considering the mentioned constant change in the API and still a bit barebone documentation, I think I will look otherwise to implement my project. Since it is a university project with a deadline, I would rather build on something that is proven and more popular with plenty of examples and guides.

While it does sound possible to develop a voting Web app, it also sounds like it isn’t easy to keep voter data secure, which is a the main focus of my project. Unless you make the data private of course. But there also has to be a way to tally all votes without exposing who voted for what choice. And of course the votes have to be immutable.

I also looked a lot at the Ethereum blockchain and might go for that instead, since that is proven to work for such an application, even with the downsides. A private blockchain might be a good choice here.

Nevertheless, I am very excited about this project and sincerely hope it succeeds big time. I probably won’t do my project with it due to the time constraints and difficulty, but I’ll definitely follow SAFE and hopefully do something in the future :slight_smile: and I will definitely mention it in the publication and maybe get a few more people’s attention for this project.

Thank you!

4 Likes

This is sensible, and hopefully you’ll keep an eye on SAFE in the future.
Have you came across Enigma in your research yet? This article may be interesting to you: https://blog.enigma.co/secret-voting-an-update-code-walkthrough-605e8635e725

1 Like

I actually have not. It looks very interesting though, thank you for pointing it out. Might be very useful!