An example of a simple blockchain app written entirely in JavaScript with Hyperledger Sawtooth. Transfer Chain allows users to create named assets and transfer them between different owners designated by a public key.
This repo includes a Transaction Processor which will can interface with a Sawtooth validator and handle validation of transactions, and a simple browser-based client which can manage public/private key-pairs and submit transactions to the Sawtooth REST API.
This project requires both Docker and Node/NPM. After installing, download this repo and run the following commands to install dependencies for the transaction processor:
cd {project directory}/processor
npm install
And these commands to install dependencies for and build the client:
cd {project directory}/client
npm install
npm run build
Use the included docker compose file to spin up some default Sawtooth components, including a validator and a REST API. Full instructions are available in the Sawtooth Documentation, but all you really need to know is, from the project directory, run this command to start Sawtooth up:
docker-compose up
And run this command to shut them down:
docker-compose down
Once running, you should be able to access the validator at
tcp://localhost:4004
and the REST API at http://localhost:8008
.
In a new terminal window, start up the transaction processor:
cd {project directory}/processor
npm start
Start the client simply by opening client/index.html
in any browser.
Users are just public/private key-pairs stored in localStorage. Create one from the "Select User" dropdown. You can use this same dropdown to switch between multiple users in localStorage.
Simple type in the name of your asset under "Create Asset" and click the create button. If you selected a user, you should see that asset appear in the list at the bottom.
Any asset you own can be transfered to another public key using the dropdowns under "Transfer Asset". Note that the transfer must be accepted by that user before it is finalized.
Any pending transfers for the selected user will appear under "Accept Asset". These can be accepted (with an immediate change in ownership) or rejected with the corresponding buttons.
This project was originally developed as an example for a talk at MidwestJS 2017: Blockchain App Development with JavaScript and Hyperledger Sawtooth. The slides for this talk are available online: