How to get a fee from NFT minters

Does anyone knows how to get a fee from NFT minters?

I’m creating NFT marketplace. Every user can mint their NFTs. This part is ok. It’s working with below code.
But I have no idea how can I get a fee.
For example, I will get 1 MATIC when user mint their token.

Maybe I need to send 1 MATIC to owner’s address. Ideally I wanna pop up the 1 MATIC message on Metamask before user minting.

How can I do that?

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract NFTCryplo is ERC1155, Ownable {
  mapping(uint256 => address) private minters;

  constructor() ERC1155(""){}

  function mint(address account,uint256 id,uint256 amount) public {
    require(minters[id] == address(0) || minters[id] == msg.sender);

    if(minters[id] == address(0)) {
      minters[id] = msg.sender;

  function uri(uint256 _id) override public pure returns (string memory) {
    return string(

You can add a require statement to your mint function to handle that and also make the function a payable function
require(msg.value >= 10, "Not enough MATIC sent; check price!");

  • This require statement requires that the payable function receive at least 10 wei, else the function will fail and revert. The msg.value parameter is the MATIC value of amount sent in alongside the mint function.

You can then transfer the paid MATIC to a specific address immediately or add another function to withdraw the MATIC later

1 Like

Thank you for your reply.

I added like this.

uint MINT_PRICE = 1 ether;  // it will be counted as 1 MATIC

require(msg.value >= MINT_PRICE, "Not enough MATIC sent; check price!");

But I’m still not sure how users pay the 1 MATIC when they mint.
Is it paid by priority fee?

You need to consider that from your client side. Using ExecuteFunction, you need to add msgValue: Moralis.Units.ETH("1") to your params , this will ensure the user executing the function is charged 1 $MATIC

1 Like

YES! it works!

Thank you very much.