My Blockchain Decentralized application for Music Industry
I have come to know about the workings of a Blockchain in the last November. I have participated in a blockchain hackcathon hosted in my university. Prior to that, whenever someone mentioned the word ‘Blockchain’, I would say, “Oh, that bitcoin thingy…” It’s more than just an application for crypto-currencies. Blockchain seamlessly enforces ‘trust’ in a system or an industry, giving out value in the form of transparency. This post is about the blockchain DApp I have built in that hackathon.
To get started, let me briefly go over the problem we are working on. We are going to develop a simple blockchain web application for the music industry. The result of this app is expected to cut out the middlemen in music industry, like labels and publisheres, enabling the artists to directly publish their creations and get rewarded rightly. For more motivation on what a blockchain could do in music, have a look at this article on the same.
Okay, jump in. We are going on a ride to develop a cool simple webapp addressing the problem, where you get to take away some basic knowledge on tech relating to blockchain and understand the working of it.
The goals of this post is to :
- Familiarize yourself with blockchain and learn the basics
- Build a simple smart-contract on the problem
- Assess the workings and limitations of the application
Sounds fun? Buckle up!
1. Technologies involved
We will be using ethereum for the blockchain and ipfs for storing the songs on a p2p network. If you don’t have previous knowldge about writing a basic smart-contract, or with truffle framework, you should first go through these part1, part2, part3 tutorials for initial set up, installing the dependencies and deploying a basic smart-contract, as we won’t be discussing them here. After that, we will learn how to install and play with ipfs.
In those tutorials I mentioned, ipfs was not used. We are going to set up ipfs which is required for out dApp.
Download ipfs for your system, unzip it. Execute the following commands to install and initiate ipfs on your system.
$ cd ipfs // go to ipfs directory
$ sudo install.sh // installs ipfs
$ ipfs init // initialises ipfs
So, now we have ipfs on our system! Now we need to set a few variables to remove conflicts in ethereum and ipfs gateway ports and CORS. Execute the following commands in your terminal.
$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT" , "GET" , "POST" , "OPTIONS"]'
$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
$ ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8082
$ ipfs config Addresses.API /ip4/127.0.0.1/tcp/5002
$ ipfs daemon // starts ipfs daemon
3. The Application
Phew! That’s a lot of work huh? Anyway, we have just learned how to build a basic smart-contract from those tutorials and set up our system for the coming application. We have just started :P
From the knowledge you gained in those tutorials, this following application code should be self explanatory. You can find all the files in my github repo.
If you were able to successfully deploy the samrt-contract from those tutorials, this is nothing different.
Clone the code from github repository using:
$ clone https://github.com/srirambandi/mediaStore.git
The code in the above file describes all the data structures and functions to handle the logic we aimed to create(publish music and record transactions).
This file has the code to call the smart-contract functions, read/write to it. From the 10 test ethereum accounts created using testrpc, we will use first 3(0,1,2) accounts for identifying singers and the rest of them(4–9) for customers. This can be handled by successfully using metamask in chrome extensions(not in safari), but we handled it this way due to limitation of time in hackathon.
Start the App!
Now that we have set everything and gone through the code, let’s start the app. Finally!
Run the following commands in your project directory to compile and deploy the samrt-contract, start the node server and ipfs :
$ cd mediaStore // enter the directory
$ node_modules/.bin/testrpc // start ethereum with 10 test accounts(in another terminal window)
$ truffle migrate --reset // compile the smart-contract
$ npm run dev // start the node js server(in another terminal window)
$ ipfs daemon // start ipfs daemon
Now go to http://localhost:8080 in your browser. Like I said, first 3 accounts are for artists and rest are for consumers.
You will be defaulted to ‘0’ account, the first account of an artist. An artist can choose song, set title and price, and upload songs. In addition he can view transaction logs from the blockchain and his wallet. A customer can browse artists, select songs and buy them, and add money to his wallet.
Additional features :
Bringing in IPFS added another most valuable feature. Try uploading a song twice from two different accounts(or same account), you will be denied the upload a second time. This has to do with how ipfs stores and indexes your data. IPFS generates a unique cryptographic hash, a digital fingerprint. This important method denies duplicate uploads! Cool, right?!
To summarize, we have learnt on how to set up environment, write a basic smart-contract from some good tutorials. We then explored a simple smart-contract focussing on the problem of publishing in music industry. You did some awesome learning there, rejoice!
We have only made a basic dApp just to demonstrate how a smart-contract might look like for this scenario. This has many limitations, it hasn’t included licenses. Even though ipfs denies duplicates, one can tamper the media data little bit and get away with a new hash. For implementing a real production ready dApp, one has to fight these challenges. There are various technologies available for identifying the similarities in media. Integrating them, and designing smart-contracts to handle licenses and payment splits adds value to your application.
I haven’t really gone through any business dynamics in explaining this tutorial. I wanted just keep it to the tech dimension :).
It was a relief to move away from the ‘bitcoin thingy’ understanding of the blockchain and to learn something. It has been a pleasure discussing these topics with you. If you run into any issues in testing the application, feel free to reach me on Facebook @srirambandi
Ciao for now!