Storing files using Storj blockchain

Recently, Peet (CTO) and I spent some time together to see how we can store data on the Storj blockchain.

When storing data on Storj network/blockchain, data blocks are encrypted and distributed across a distributed set of storage nodes.

But why store data on a blockchain ?

Use cases include things like storing financial advice for non-repudiation purposes

Storing a piece of advice on a blockchain is a guarantee that no one can change it once it has been recorded and it can be easily encrypted as an extra bonus (smile).

Storj Bridge provides an easy to use rest API for accessing the blockchain network, but during our POC we used NPM packages to interact with the api.

To get started all that’s needed is: npm install -g storj

We followed the tutorials and after few minutes we were able to upload an encrypted file to the blockchain. Next we retrieved the file to check its validity.

All went quick and easy without any major impediments  (thanks to Peet’s magic skills (smile); I’ve been mostly a spectator) and we found working with the Storj API a nice experience.

The actions we did are summarised below:

  • create a user and login on the network
  • create a private key
  • create a bucket
  • upload a file to the bucket
  • retrieve the file from the bucket

Below is a sample code that we used in our test (more examples here). The script used to interact with the Storj blockchain is checked in git at storj-demo

'use strict';
var storj = require('storj-lib');
// Set the bridge api URL
var fs = require('fs');
var through = require('through');
var api = 'https://api.storj.io';
// Create client for interacting with API
var client = storj.BridgeClient(api);
//...............................................................

var authenticate = () => {
    var keypair = storj.KeyPair(fs.readFileSync('./private.key').toString());
    // Login using the keypair generated
    return storj.BridgeClient(api, {keyPair: keypair});
}

var listBuckets = (client) = {
    client.getBuckets(function(err, buckets) {
        if (err) {
        // Handle error on failure.
           return console.log('error', err.message);
        }
        if (!buckets.length) {
           return console.log('warn', 'You have not created any buckets.');
        }
        // Log out info for each bucket
        buckets.forEach(function(bucket) {
          console.log(
            'info',
            'ID: %s, Name: %s, Storage: %s, Transfer: %s',
            [bucket.id, bucket.name, bucket.storage, bucket.transfer]
          );
        });
     });
}
//...............................................................

We will continue experimenting with blockchain and see what benefits it might bring to us!

One last thing: here’s the file we uploaded during our experiment, thanks Winston for support! (smile)

winston

P.S.: the character in the image is Winston. He has loads of cool tech like a jump pack, electricity-blasting Tesla Cannon, portable shield projector and more—with literal gorilla strength.

P.P.S. Blockchain is boring but you like Winston? Here you go, have some more (smile)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s