Skip to content

Pash10g/stitch-blockchain

Repository files navigation

stitch-blockchain

Demo for MongoDB stitch as a store for blockchains

Introduction

Revolutionary Blockchain technology meets MongoDB’s empowering backend service and Database for modern applications to create next generation solutions. Using Stitch platform will allow us to design and build the next decentralize, trusted and fraud free applications utilizing its newest features.

Overview

  • In this workshop you will get to see live coding and build a hands-on application that is build with Stitch implementing a decentralized blockchain application. You will be able to use newest Stitch features such as Advanced Javascript functions and event driven notifications (Change Streams).

  • The nodes will use the anonymous Stitch authentication consuming only public information. Each node is allowed to edit only its information while the node consensus will be enforced by Stitch functions. Notifications will be the main component that notifies subscribers and pushes the processes forward until completion.

  • End peers (example bank accounts) may use a variety of authentication mechanisms available by Stitch to keep their data private and encrypted.

Prerequistes for the demo

  1. You should have a 3.6+ Atlas cluster running with a new stitch app in place.
  2. We are using the following 3rd party service for the demo

Configuring and running

  1. Setup an Atlas cluster and stitch. See the following documentation.
  2. Import the stitch skelaton app from this repo: stitch-blockchain.zip.
  3. Create the following view and index in your cluster under database transactions:
db.createView("blockchain","pending_blocks",
			[	{
					"$match" : {
						"index" : 0
					}
				},
				{
					"$graphLookup" : {
						"from" : "pending_blocks",
						"startWith" : "$previousHash",
						"connectFromField" : "hash",
						"connectToField" : "previousHash",
						"as" : "chain"
					}
				},
				{
					"$unwind" : "$chain"
				},
				{
					"$sort" : {
						"chain.index" : 1
					}
				},
				{
					"$group" : {
						"_id" : "$_id",
						"chain" : {
							"$push" : "$chain"
						}
					}
				},
				{
					"$project" : {
						"chain" : 1,
						"_id" : 0
					}
				}
			]);

db.pending_blocks.createIndex({index : 1},{unique : true});

  1. Create a mongodb readWrite user on databases: transactions,assets. Verify that the cluster name in the imported application is associated with your cluster name.
  2. Edit the main.js file with the MongoDB credentials created in step 4 and the correct connection string for your Atlas cluster/ Stitch appId. Run the production of the blocks and Spin as many nodes as you see fit (Remember to whitelist your nodes IP's to the Atlas cluster). Remember they are scalable:
npm install
node main.js
  1. Create a stitch email/password credentials through Authentication tab. Make sure that you update "values" stitch entry named ipstack_access_token with value that equals to the ipstack access token you have.
  2. Edit the dummy stitch-blockchain/app.js application with your stitch , edit stitch-blockchain/mobileendpoint.html and replace with your mapbox token.
  3. Open the application stitch-blockchain/mobileendppoint.html and input the credentials created in step 6. The blockchain should now work.

About

Demo for MongoDB stitch as a store for blockchains

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published