Section 1 Introduction

Welcome to build a decentralized e-commerce DApp with ethereum development! We will build an online e-commerce application similar to Taobao, where sellers can sell goods freely and buyers can shop freely:

  1. Decentralized: Unlike Taobao or eBay, we put all of our business logic and core data on the Ethereum blockchain, which makes it a completely decentralized application. Compared to centralized e-commerce platforms like Taobao, a decentralized P2P e-commerce app clearly has its own unique value — at least you don’t have to worry about being blocked by the platform.

  2. IPFS: Storing images and descriptive hypertext for product presentations on Ethereum is expensive and sometimes not feasible due to the limitations of the Ethereum VIRTUAL machine. To solve this problem, we will store the product images and product descriptions in the same decentralized interplanetary file System (IPFS), and only keep the ids of the data on the chain.

  3. Commodity auction: for sellers, auction is obviously a very good means of sales to improve the profit margin of commodities. So in the course project we will implement a Decentralized Vickery auction — very similar to eBay’s automated bidding system, rather than simply putting a fixed price on an item.

  4. Money custody: One advantage of a centralized platform is that it provides a natural intermediary of trust between buyers and sellers. In a decentralized environment, we will address the risks of both buyers and sellers by using a multi-party escrow contract, which uses a voting mechanism to determine where the buyer’s money ends up.

  5. Off-chain data storage: Don’t let decentralization limit our thinking, traditional technologies still have their strengths. We will use MongoDB to do a synchronous backup of data down the chain in order to achieve something that is difficult to achieve with blockchain alone: flexible commodity query.

Courses address: xc.hubwiz.com/course/5abb…

Section 2 Decentralization, Why?

Before we start building our app, it’s worth taking a minute to understand why we want to build an online marketplace on a decentralized platform like Ethereum.

Consumer-to-consumer e-commerce platforms like eBay or Taobao have been hugely successful because they make it very convenient for both buyers and sellers:

Before the Internet became mainstream, people could only buy and sell goods in small areas or between neighbors. As more and more people use the Internet, there are platforms like eBay, where you can buy and sell goods online, no matter where you are in the world. Such platforms have value for both merchants and consumers.

While a platform like eBay is convenient and improves trade and the economy, it also has some disadvantages:

  1. Bound by the platform. Participating merchants are subject to the business that owns the platform. At any time, the platform owner can decide whether to ban a merchant or not, and if a merchant is heavily platform dependent, an account ban can be a huge blow.

  2. Merchant fees are high. Merchants pay a fee to put goods on the shelves and a commission to sell them. There is nothing inherently wrong with charging, as platforms like eBay provide services. But listing fees are sometimes so high that merchants end up making little profit or passing the cost on to consumers.

  3. Data is out of control. Neither businesses nor consumers can own the data that should be their own. Reviews, purchase history, and all data are owned by the platform owner. For example, if a business wants to switch providers, or wants to export product reviews or other data, it is very difficult, if not impossible.

Decentralized e-commerce platforms built on Ethereum solve these problems: merchants can’t get their accounts blocked; The data is also public, so it’s easy to export; Trading commissions are also much lower compared to centralised platforms.

Section 3 Preliminary functional features

Now that you understand why we’re building a decentralized e-commerce application and what we’re building, let’s take a look at the main features that will be implemented in this project:

  1. Listing: Apps should allow sellers to list products for sale. We’re going to have the ability for anyone to put anything on the shelf.

  2. Product browsing and search: The app should allow the buyer to easily browse the product list. We will realize the function of browsing goods, as well as the query function based on the category of goods, auction time and other conditions.

  3. Goods auction: Like eBay, we will implement vicory auction for goods bidding. Since all transactions on Ethereum are public, our implementation will be different than in a centralized environment.

  4. Fund escrow: Once the bidding ends and there is a winner in the commodity auction, we will create an escrow contract involving the winning buyer, seller and any third party to manage the transaction funds.

  5. Escrow Funds protection: In order to protect escrow funds, we will use multiple signatures (2/3) to protect against fraud, that is, only when two of the three participants agree, escrow funds will be released to the seller, or escrow funds will be returned to the buyer.

To facilitate the query, we will store the commodity data both on and off the chain (database); At the same time, to avoid expensive on-chain storage of data such as images, we will upload images and product descriptions to the same decentralized IPFS network.

Courses address: xc.hubwiz.com/course/5abb…

Section 4 Basic Knowledge Requirements

In order to successfully complete this course, you should have some knowledge of the following languages/technologies:

  1. Solidity/Truffle: The course will drill down on writing contracts using Solidity. If you haven’t already, I suggest you take a look at the Ethereum DApp Tutorial so you’ve written at least a simple contract or two. A basic understanding of the Truffle development framework will also be helpful in completing this course.

  1. HTML/CSS/JavaScript: There will be more HTML and CSS code in this course than in the introductory course. You should have a basic understanding of building a front end using HTML/CSS. In the meantime, we’ll use JavaScript further. It saves the data to the database on the server side, queries the database, and returns the results to the front end. Web3.js is used for front-end interaction with blockchain. We’ve kept the JavaScript code as simple as possible for learners of all backgrounds.

  1. Database: We will use MongoDB to store product information under the chain. No special knowledge of MongoDB is required, but a basic database knowledge will help you navigate this course.

Section 5 System architecture

Before starting with the concrete implementation, let’s take a look at the architecture of the decentralized e-commerce DApp that we will build in this course.

  1. Web front End: The Web front end is developed using HTML/CSS/JavaScript, which makes heavy use of Web3JS to access the blockchain. Users will access Ethereum, IPFS, and NodeJS servers through this front-end application.

  2. Ethereum blockchain: This is the core of decentralized applications. All codes (e-commerce contracts, fund custody contracts) and transactions are stored on the chain, including all commodity information, buyer’s bidding information, commodity bidding results, fund flow voting results, etc.

  3. MongoDB: Although the core data is stored on the block chain, in order to facilitate buyers to search and query goods, such as only displaying a certain type of goods, or displaying goods that are about to expire, we will use MongoDB database to store and retrieve goods information synchronously.

  4. NodeJS server: This is the back-end server that we will use to provide a REST-style API to the front end to query items, and also to respond to requests for static pages on the front end.

  5. IPFS: When the seller lists a product, the front end will upload the product picture file and introduction text to IPFS, and save the hash value of the uploaded file to the chain.

Section 6 Understand the role of architecture

To help understand the components discussed in the previous section, let’s look at the process by which a seller lists an item:

  • (1) The front end uses an HTML form to collect commodity details input by users, such as starting price, commodity picture, description information, etc.

  • (2)(3) The front end uploads the product picture and introduction text to IPFS and returns the corresponding link (hash) of the uploaded content.

  • The Web front end then invokes the e-commerce contract to store the product information and IPFS link on the chain. When the contract successfully deposits an item onto the blockchain, it triggers an event that contains all the information about the item.

  • NodeJS server listens for blockchain events, and when the event is triggered by the e-commerce contract, the server reads the event content and inserts the commodity information into the MongoDB database.

We’ll revisit this process when we start concretely implementing the product listing feature.

Section 7 Agile Development

We will adopt the idea of agile development to realize decentralized e-commerce DApp:

We split all product features into eight iterations, and with each sprint we got a releasable version:

The first two sprints focus on implementing e-business contracts using the Solidity and Truffle frameworks, which includes contract design, development, compilation, deployment and testing:

  • Sprint-1: product listing and display method for e-commerce contracts.

  • Sprint-2: Commodity bidding and bid disclosure methods for implementing e-commerce contracts. After the e-commerce contract is basically realized, the next three sprints are mainly focused on the construction of the front-end user interface, including the use of Web3 to interact with the contract, as well as data interaction such as uploading pictures through the IPFS development interface, and of course, the essential DOM operation:

  • Sprint-3: Product browsing interface for buyers.

  • Sprint-4: Provide the operation interface for sellers to put their products on the shelves.

  • Sprint-5: Provides the buyer with an item detail interface, a bidding form, and a bid disclosure form. In the next two sprints, we will first implement a fund custody contract, which manages the winning buyer’s money after the auction. Then the corresponding user operation interface is realized.

  • Sprint-6: Implement fund custody contract.

  • Sprint-7: Provides an operating interface for the participating parties under the fund trusteeship contract. Finally, in order to facilitate the query and retrieval of goods, we will use MongoDB to realize the down-chain storage of commodity data.

  • Sprint-8: Realize data synchronization and data query under the chain.

Courses address: xc.hubwiz.com/course/5abb…

There are also courses to choose from:

Python Ethereum is designed for Python programmers to develop blockchain Ethereum around the Web3.py library:

Xc.hubwiz.com/course/5b40…

Web3j, mainly for Java and Android programmers around the Web3J library for blockchain Ethereum development:

Xc.hubwiz.com/course/5b2b…

PHP Ethereum, mainly introduces the use of PHP for smart contract development interaction, account creation, transactions, transfers, token development, filters and events, etc. :

Xc.hubwiz.com/course/5b36…

C# ethereum, mainly explains how to use C# based development. Net ethereum applications, including account management, status and transactions, smart contract development and interaction, filters and events, etc. :

Xc.hubwiz.com/course/5b60…

Ethereum tutorial, mainly introduces smart contract and DApp application development, suitable for starting:

Xc.hubwiz.com/course/5a95…

Introduction to EOS Smart Contract and DApp Development

Xc.hubwiz.com/course/5b52…