what im i doing wrong here, this is smart contract based on e-commerce that allow users to create store list goods and sell. im getting the above error on line 61
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
//import "hardhat/console.sol";
contract MarketPride {
address payable owner;
uint256 productCounter;
struct Product {
string title;
string category;
string description;
address payable seller;
uint256 price;
uint256 rating;
uint id;
uint256 timestamp;
}
products[++productCounter] = newProduct
//creating an object of all store
struct storeStruct {
string name;
string description;
uint256 id;
address creator;
}
Product[] products;
mapping (uint256 => Product) public productById;
mapping (uint256 => storeStruct) public stores;
constructor () {
owner == msg.sender;
}
modifier onlyStoreOwner() {
require(owner == msg.sender , 'only store owner can delete a store');
_;
}
event payment(
address indexed _from,
address indexed _to,
uint256 _price
);
function checkUserExist(address pubkey) public view returns(bool){}
function createStore(string calldata _name, string calldata _desc) public view{
require(checkUserExist(msg.sender) == false, 'pls register an account first');
require(bytes(_name).length>0, "Store name needs to be included");
require(bytes(_desc).length>0, "description plays an important role");
}
function listProductToStore(
string memory _name,
string memory _category,
string memory _description,
address payable _price,
uint256 _rating,
uint256 _time) public {
require(checkUserExist(msg.sender) == false, 'pls register an account first');
Product memory newProduct = Product({
buyer: address(0),
seller: msg.sender,
id: products,
name: _name,
category: _category,
description: _description,
price: _price,
rating: _rating
});
}
function payForProducts(address _from, address _to, uint256 price) public payable {
}
function getAllStore() public view returns(storeStruct[] memory){}
function getAllProduct() public view returns(Product[] memory){}
function getStoreName(address pubkey) external view returns(string memory){}
}
Best Answer
I am not sure why you created your struct instance with the name
Product
when you have created the struct with the nameproductStruct
. Replace your line 61 with:Also, seems like you are not storing your struct instance anywhere. Make sure to update that too.
UPDATE: The final code: