Skip to content

Instantly share code, notes, and snippets.

@kharioki
Created October 4, 2021 21:59
Show Gist options
  • Save kharioki/b0fca8b2e3499de5e7ffbb3268b04b0e to your computer and use it in GitHub Desktop.
Save kharioki/b0fca8b2e3499de5e7ffbb3268b04b0e to your computer and use it in GitHub Desktop.
A marketplace smart contract with solidity
// 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