1

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 61an e-commerce smart contract

// 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){} }

1
  • Please, include the code as text. It is much easier for testing than using an image.
    – Ismael
    Commented Nov 22, 2022 at 7:02

1 Answer 1

2

I am not sure why you created your struct instance with the name Product when you have created the struct with the name productStruct. Replace your line 61 with:

productStruct memory newProduct = productStruct({ ...

Also, seems like you are not storing your struct instance anywhere. Make sure to update that too.

products[++productCounter] = newProduct

UPDATE: The final code:

productStuct memory newProduct = productStuct({
        buyer: address(0),
        seller: msg.sender,
        id: products,
        name: _name,
        category: _category,
        description: _description,
        price: _price,
        rating: _rating
    });
    products[++productCounter] = newProduct
9
  • where should i add lhe 2nd code you wrote
    – Josephdev
    Commented Nov 22, 2022 at 10:27
  • Just below the struct Commented Nov 22, 2022 at 10:30
  • Linter: Parse error: extraneous input '=' expecting {'from', 'error', 'calldata', 'revert', 'callback', 'override', 'constant', 'immutable', 'leave', 'internal', 'payable', 'private', 'public', 'constructor', 'receive', Identifier} [undefined] Expected identifier but got '='
    – Josephdev
    Commented Nov 22, 2022 at 10:44
  • i just updated the question with an original code as text can you pls check it out and hlp
    – Josephdev
    Commented Nov 22, 2022 at 10:48
  • Updated my answer Commented Nov 22, 2022 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.