0

I want to create a market place of nfts. I know how to mint and creat nft but I dont know how to set price of token, how to set list of orders. I read that the price should be set on token contract address. Then how can I set price to token contract address and how to update that price because each user(a person who owns the nft) want to sell as a different price. Should I save the price and list of orders in my database or I should set them on token contract address or maybe in nft?

1 Answer 1

0

If you are on a marketplace, you can define an Nft marketplace item the way you want it:

struct NftItem{
    uint tokenId;
    uint price;
    address creator;
    bool isListed;
  }

You can write a _createNft function:

function _createNftItem(uint tokenId,uint price) private{
    require(price > 0, "Price must be at least 1 wei");
    // depends on how you wanna store the nft
    idToNftItem[tokenId]=NftItem(
      tokenId,
      price,
      msg.sender,
      true
    );
    emit NftItemCreated(tokenId,price, msg.sender,true);
  }

when you call the mint function, you can pass price arg, you call _createNftItem function

function mintToken(string memory tokenURI,uint price) public payable returns (uint){
    require("write logic this tokenUri was not used before");
    require("make sure sender is sending the lsiting price");
    _tokenIds.increment();
    _listedItems.increment();
    uint newTokenId=_tokenIds.current();
    // this is a wrapper for _mint
    _safeMint(msg.sender,newTokenId);
     // minting will create an item on blockchain
     // createNftItem is specific to marketplace
    _createNftItem(newTokenId,price);
    
    return newTokenId;
  }

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.