Created
October 4, 2021 21:59
-
-
Save kharioki/b0fca8b2e3499de5e7ffbb3268b04b0e to your computer and use it in GitHub Desktop.
A marketplace smart contract with solidity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity >=0.7.0 <0.9.0; | |
contract Marketplace { | |
uint internal productsLength = 0; | |
struct Product { | |
address payable owner; | |
string name; | |
string image; | |
string description; | |
string location; | |
uint price; | |
uint sold; | |
} | |
mapping (uint => Product) internal products; | |
function writeProduct( | |
string memory _name, | |
string memory _image, | |
string memory _description, | |
string memory _location, | |
uint _price | |
) public { | |
uint _sold = 0; | |
products[productsLength] = Product( | |
payable(msg.sender), | |
_name, | |
_image, | |
_description, | |
_location, | |
_price, | |
_sold | |
); | |
productsLength++; | |
} | |
function readProduct(uint _index) public view returns ( | |
address payable, | |
string memory, | |
string memory, | |
string memory, | |
string memory, | |
uint, | |
uint | |
) { | |
return ( | |
products[_index].owner, | |
products[_index].name, | |
products[_index].image, | |
products[_index].description, | |
products[_index].location, | |
products[_index].price, | |
products[_index].sold | |
); | |
} | |
function getProductsLength() public view returns (uint) { | |
return (productsLength); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment