Git Product home page Git Product logo

coffeechain-backend's Introduction

Coffeechain

What is it?

Coffeechain aims to connect specialty coffee producers and coffee shops and support direct and fair trade. It is a decentralized market place providing a trustless system with blockchain. Intermediaries are removed and no third party is involved.

When I speak about it in the West, people say they trust Google, Facebook, or their banks. But the rest of the world doesn't trust organizations and corporations that much — I mean Africa, India, the Eastern Europe, or Russia. It’s not about the places where people are really rich. Blockchain's opportunities are the highest in the countries that haven’t reached that level yet. - Vitalik Buterin, inventor of Ethereum

Screenshots and details

All available coffees


Coffee shops


My orders

Getting started

Prerequisites

  • Either Ubuntu 18.04 or MacOS Darwin or higher. Other operating systems will not work, sorry.
  • Docker
  • Node.js
  • Stripe API keys
  • You will also need the Coffeechain client if you want any sort of useful interaction with the application.

Run the app

With default settings, the app, eosio, redis and MySQL will occupy the ports 3306, 4000, 5555, 6379 and 7777. Make sure nothing else is running on these ports or change them when creating the .env file.

  1. First, clone the repository and create a .env file as shown in .env.example:
git clone https://github.com/leonhfr/coffeechain-backend.git
cd coffeechain-backend
cp .env.example .env
# Atom or your favorite editor:
atom .env
# Adjust variables, add Stripe keys.
# Save the file.
  1. Then, run the script blockchain.sh: sh blockchain.sh

The above script will:

  • Check that you have Docker and Node.js installed
  • Install backend dependencies (npm install)
  • Pull a redis image and start it
  • Pull a MySQL image and start it
  • Pull an eosio/eos image and start it
  • Start a private EOS blockchain and configure it
  • Deploy the beancoin smart contract
  • Populate the database and the blockchain with mock data
  • Start the backend API server (npm start)

Troubleshooting

  • Docker needs to be able to run without sudo.
  • You may need to make the scripts executable. Run this command from the coffee-blockchain-backend directory:
chmod +x blockchain.sh \
  ./blockchain/scripts/redis.sh \
  ./blockchain/scripts/mysql.sh \
  ./blockchain/scripts/eosio.config.sh \
  ./blockchain/scripts/eosio.data.sh \
  ./blockchain/scripts/eosio.start.sh

Stop the app

In the terminal, press ctrl+c on your keyboard. Then run: sh blockchain.sh stop

You can check with docker ps whether some containers are still running.

Useful stuff

The backend and the frontend are already configured to interact with the blockchain. However, should you wish to interact with it directly, the easiest way is to alias the docker exec command to avoid having to enter the Docker containers' bashes every time.

# For MySQL:
alias sqlcoffee='docker exec -it mysql_coffeechain mysql -u root --password=[your DB_PASS from .env]'
# For the eosis/eos image:
alias cleos='docker exec -it eosio_coffeechain /opt/eosio/bin/cleos --url http://127.0.0.1:7777 --wallet-url http://127.0.0.1:5555'

Please note that the aliases will only be valid within your current terminal. To save them permanently add them to your ~/.bash_profile.

For interacting with cleos, the blockchain.sh script saves the password of the eosiomain and beancoin wallets to the folder /blockchain/data, you may need them to unlock the wallets. You should also take a look at the mock keys in /blockchain/scripts/mock.data.user.json.

How does it work?

In this project, the blockchain is used as the single source of truth.

We are building on EOS. EOS is a blockchain that acts like a decentralized operating system. It specializes in smart contracts and allows very high performance and throughput of several millions of transactions per second with no transaction fees.

We are deploying a smart contract called beancoin. The smart contract acts like a normal contract but does not need any third party. It is autonomous and self-enforcing. Beancoin oversees the interactions between producers and customers. It is public, so that everyone knows by which rules to abide.

The state of the smart contracts is stored in the blockchain: users, the coffees available and the sales that have been made and their status. The problem is that blockchain is good for trustless decentralized systems, but that it is expensive to store data in it and hard to query like you would with a traditional API.

In this project, when a user sends data, it is stored in the database. A md5 hash of the data is sent to the blockchain. If the hash of the data stored in the blockchain matches the hash of the data sent to the database, we know that the query is trustworthy and that the user authorized it. The data is then served back to the user via a traditional API that allows complex queries. Conversely, the user can also query the blockchain to verify that the hashes match the data it received from the database.

Future features

  • Authentication using Scatter
  • Payments via a decentralized network like EOS or Stellar
  • Shipping
  • Reviews
  • Messaging

Tech Stack

Blockchain:

Back-end:

Front-end:

Authors

coffeechain-backend's People

Contributors

leonhfr avatar tezenn avatar adriapalleja avatar chinins avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.