-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmart-Contract-Basic.sol
42 lines (32 loc) · 1.22 KB
/
Smart-Contract-Basic.sol
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
pragma solidity ^0.8.0;
contract HalalMarketplace {
address public owner;
// Event for product added
event ProductAdded(uint productId, string name, uint price, address vendor);
struct Product {
uint id;
string name;
uint price;
address vendor;
bool isHalal;
}
Product[] public products;
// Halal certification (For simplicity, hardcoded here. Expand with AI or DB integration.)
mapping(uint => bool) public halalCertified;
constructor() {
owner = msg.sender;
}
function addProduct(string memory _name, uint _price, bool _isHalal) public {
uint productId = products.length;
products.push(Product(productId, _name, _price, msg.sender, _isHalal));
// Emit the product added event
emit ProductAdded(productId, _name, _price, msg.sender);
}
function buyProduct(uint _productId) public payable {
Product storage product = products[_productId];
require(msg.value >= product.price, "Insufficient funds");
require(product.isHalal == true, "Product not Halal");
// Transfer payment to vendor
payable(product.vendor).transfer(product.price);
}
}