-
Notifications
You must be signed in to change notification settings - Fork 0
/
Marketplace in celo
119 lines (87 loc) · 2.34 KB
/
Marketplace in celo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
contract Marketplace {
string public product = "Burger";
}
contract Marketplace {
string internal product;
function writeProduct(string memory _product) public {
product = _product;
}
}
contract Marketplace {
string internal product;
function writeProduct(string memory _product) public {
product = _product;
}
function readProduct() public view returns (string memory) {
return product;
}
}
contract Marketplace {
mapping (uint => string) internal products;
function writeProduct(uint _index, string memory _product) public {
products[_index] = _product;
}
function readProduct(uint _index) public view returns (string memory) {
return products[_index];
}
//spdx-licesne-identifyer: MIT
pragma solidity >=0.7.0 <0.9.0;
contract marketplace {
uint internal productsLenght = 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[Productslenght] = product(
payable(msg.sender),
_name,
_image,
_description,
_location,
_price,
_sold
);
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
interface IERC20Token {
function transfer(address, uint256) external returns (bool);
function approve(address, uint256) external returns (bool);
function transferFrom(address, address, uint256) external returns (bool);
function totalSupply() external view returns (uint256);
function balanceOf(address) external view returns (uint256);
function allowance(address, address) external view returns (uint256);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
contract Marketplace {
function buyProduct(uint _index) public payable {
require(
IERC20Token(cUsdTokenAddress).transferFrom(
msg.sender,
products[_index].owner,
products[_index].price
),
"Transfer failed."
);
products[_index].sold++;
}
function getProductsLength() public view returns (uint) {
return (productsLength);
}
}