Skip to content

alessandro308/CryptoMarket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CryptoMarket

CryptoMarket Logo

CryptoMarket is a prototype. It is a Marketplace that runs over the Etherem Blockchain. It is able to manage products (and orders, too).

Since it runs over the blockchain it doesn't need to have any server.

How use it

You can run it by yourself or use my hosted files here. In order to run this files you have to use something that inject Web3 into the webpage, the simplest way is to use Chrome with MetaMask Extension installed.

Remember, if you would like to use your machine to use it, you have to run a webserver (and not file://), otherwise MetaMask cannot inject the code due security restrictions.

Contract

The contract is developed using Solidity. It is actually deployed over Rinbeky Ethereum Test Net. You can you this code to understand how Solidity works. In order to deploy your own contract, you can refers to this page.

API

getOwnOrders() returns(uint[])

Returns the ids of the orders that refers to product sold by the msg.sender.

getProductIdsBySeller(address _seller) returns(uint[])

Returns the ids of product sold by specific address.

buyProduct(uint _id, uint32 _quantity, string _shippingAddress) payable

Is the only payable function of the contract. If the msg.value is equal to the price of the product with id equals to _id, then decrease the product avaiable quantity and create an order.

orders

This is the dynamic arrays that stores all the orders created. The Order has the following structure

struct Order {
        string shippingAddress;
        uint32 quantity;
        uint productId;
    }
addProduct(string _n, string _d, uint _p, uint _q)

This function add a product to products dynamic array. Set the linked proprieties stored into the following self-described maps:

	mapping(uint => address) public productToSeller;
    mapping(address => uint32) public sellerProductCounter;

At the end generated the following event NewProductCreated(address seller, uint productId);.

removeProduct(uint _productId)

This function delete the product from the products array. It can be executed only by the product's seller.

What's next

The orders are not yet implemented.