Blockchain based inventory tracking. Because we need to keep track of our iPhone chargers! A quick blockchain app I created for AlephSummit2018.
-
npm i
-
node app.js
-
Navigate to
https://localhost:3001
for the client app. -
Current state of the blockchain app is at
https://localhost:3000/state
(Note the port is 3000 not 3001) -
To create a transaction send a POST to
https://localhost:3000/txs
with the following format:{ "item": "iPhone charger", "user": "John Doe" }
node app.js --dev
In this mode lotion will not attempt to connect to any peers and the blockchain will be cleared on every run. This is convenient for development because you get a fresh blockchain on every run and will not screw up the existing chain running on other nodes.
All this app does is:
-
Start with initial state:
{}
-
Accept transactions of the form:
{ "item": "iPhone", "user": "John Doe" }
-
Which will mutate state into:
{ "items": { "iPhone": "John Doe" }, "users": { "John Doe": { "iPhone": true } } }
-
Here's another transaction:
{ "item": "Macbook", "user": "Jane Doe" }
-
Which will mutate state into:
{ "items": { "iPhone": "John Doe", "Macbook": "Jane Doe" }, "users": { "John Doe": { "iPhone": true }, "Jane Doe": { "Macbook": true } } }
-
Here's another transaction where Jane takes the iPhone from John:
{ "item": "iPhone", "user": "Jane Doe" }
-
You will end up with the following state:
{ "items": { "iPhone": "Jane Doe", "Macbook": "Jane Doe" }, "users": { "Jane Doe": { "iPhone": true, "Macbook": true } } }
That's it!