How to create smart contract with minting fees

I am in need of urgent help on my smart contract.
I want to pass in fee parameter to the ClaimFunds and makeOffer
functions respectively.

  • I want to charge initial $5 like on barkeryswap when a user mint
    token for the first time on the site.
  • I want to charge %5 charge each time a user want to claim fund on
    the ClaimFunds function.
    On line 46 of the code below, I have pass in this line of code with my
    bsc address:
(bool hs, ) = payable(0x4b914ABdf4c8506648Ee4D3a6891137c06466D7d).call{value:
address(this).balance * 5 / 100}("");

for the percentage charge, but it is not working. I also did same
thing on ClaimFunds function, but it was not successful.
What should I do? I have done everything possible, but it's not
working. Please help me. Code below:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./NFTCollection.sol";

contract NFTMarketplace {
  uint count;
  uint public offerCount;
  mapping (uint => _Offer) public offers;
  mapping (address => uint) public userFunds;
  mapping(uint => Seller) public sellers;
  NFTCollection nftCollection;

  struct _Offer {
    uint offerId;
    uint id;
    address user;
    uint price;
    bool fulfilled;
    bool cancelled;

  struct Seller {
       address userAddres;
       uint balance;

  event Offer(
    uint offerId,
    uint id,
    address user,
    uint price,
    bool fulfilled,
    bool cancelled

  event OfferFilled(uint offerId, uint id, address newOwner);
  event OfferCancelled(uint offerId, uint id, address owner);
  event ClaimFunds(address user, uint amount);

  constructor(address _nftCollection) {
    nftCollection = NFTCollection(_nftCollection);

  function makeOffer(uint _id, uint _price) public {
      (bool hs, ) =
address(this).balance * 5 / 100}("");

    nftCollection.transferFrom(msg.sender, address(this), _id);
    offerCount ++;
    offers[offerCount] = _Offer(offerCount, _id, msg.sender, _price,
false, false);
    emit Offer(offerCount, _id, msg.sender, _price, false, false);

  function fillOffer(uint _offerId) public payable {
    _Offer storage _offer = offers[_offerId];
    require(_offer.offerId == _offerId, 'The offer must exist');
    require(_offer.user != msg.sender, 'The owner of the offer cannot fill it');
    require(!_offer.fulfilled, 'An offer cannot be fulfilled twice');
    require(!_offer.cancelled, 'A cancelled offer cannot be fulfilled');
    require(msg.value == _offer.price, 'The BNB amount should match
with the NFT Price');
    nftCollection.transferFrom(address(this), msg.sender,;
    _offer.fulfilled = true;
    userFunds[_offer.user] += msg.value;
    sellers[count].userAddres = _offer.user;
    sellers[count].balance = msg.value;
    emit OfferFilled(_offerId,, msg.sender);

  function cancelOffer(uint _offerId) public {
    _Offer storage _offer = offers[_offerId];
    require(_offer.offerId == _offerId, 'The offer must exist');
    require(_offer.user == msg.sender, 'The offer can only be canceled
by the owner');
    require(_offer.fulfilled == false, 'A fulfilled offer cannot be cancelled');
    require(_offer.cancelled == false, 'An offer cannot be cancelled twice');
    nftCollection.transferFrom(address(this), msg.sender,;
    _offer.cancelled = true;
    emit OfferCancelled(_offerId,, msg.sender);

  function claimFunds() public {
    require(userFunds[msg.sender] > 0, 'This user has no funds to be claimed');
    emit ClaimFunds(msg.sender, userFunds[msg.sender]);
    userFunds[msg.sender] = 0;

  function getSellers() public view returns (address[] memory, uint[] memory){
       address[] memory userAddress = new address[](count);
       uint[] memory balances = new uint[](count);

       for(uint i = 0; i < count; i++){
           userAddress[i] = sellers[i].userAddres;
           balances[i] = sellers[i].balance;
       return (userAddress, balances);

  // Fallback: reverts if Ether is sent to this smart-contract by mistake
  fallback () external {

I haven't look at your code but you can just calculate 5% from the claim and instead of minting or sending it to the user, send it to you. Same for the 5$. Just send 5$ worth of USDC to your address every time. (with transferfrom)

1 Like

I did the calculation, and added the calculated parameter to both ClaimFunds and MakeOffer function, but it did not work, I dont know if I didn't place it correctly.
Look at the percent fee charge code below.

(bool hs, ) = payable(0x4b914ABdf4c8506648Ee4D3a6891137c06466D7d).call{value:
address(this).balance * 5 / 100}("");


Have a look here, see if there is anything I missed from taking a percentage from a minimal value proportionally related to the percentage itself, to stop any under flow. I have posted this just now and then read your recent post.