Smart Contract with Mint and Payable Function (ERC20)

Hey,

I would like to create smart contract where You can mint new tokens (accesible by anyone calling) and charge a fee during that mint payable to contract creator. Something like a donation, but with the mint new tokens function at the same time.

I came up with something like this (changed onlyOwner to paybale), but how to set I believe msg.value to call a specific amount to pay during the mint. I would appreciate every answer as Im struggling with that for hours now .. thank You.

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

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyToken is ERC20, Ownable {
    constructor() ERC20("MyToken", "MTK") {
        _mint(msg.sender, 10000 * 10 ** decimals());
    }

    function mint(address to, uint256 amount) public payble {
        _mint(to, amount);
    }
}

I think you mean something like this:

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

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyToken is ERC20, Ownable {

    uint256 public donation;
    constructor() ERC20("MyToken", "MTK") {
        _mint(msg.sender, 10000 * 10 ** decimals());
    }

    function mint(address to, uint256 amount) public payble {
       require(msg.value >= donation);
        _mint(to, amount);
    }
}

You helped me a lot. I want smart contract to be accessible by anyone calling a contract, but when i remove " address to " in the mint function it says that my uint256 amount has unused function parameter. Any idea ?
What I mean is that i don't want to hard code address to mint, but I want it to make it accessible by anyone calling the contract.

Thanks

Can you clarify what you want to do and why would you remove the address to ? So far with the contract you have anybody can call it.

I want to create a smart contract where You mint token and pay for it at the same time and it should be accessible by anyone who wants to call it.

That part is clear, but why you want to remove the to parameter?

Because when i try to interact smart contract with front end the console says I need to specify To parameter

And why don't you send that parameter?

I think I understand now, you can leave the parameter and send inside the to parameter who the minting will go to, everybody can mint tokens to their own addresses like that.

May i suggest that you try and find someone or pay someone who has experience in programming solidity to create this contract for you, or alternatively spend a couple weeks learning on how to program solidity.

Even though the syntax is rather simple there are a lot of details and gotcha's you should be aware of. On simple error and people will lose access to their tokens/nfts or an hacker can take over your contract and steal them all.

From reading your questions it is clear that, right now, you do not have the knowledge to do so yourself at this time. There are a lot of good informational sources out there teaching people how to program in solidity.

Anyway it is just a suggestion and i wish you good luck with your project.

Thank You for Your answer and suggestion. I figured it out that my problem was mostly with the smart contract interaction.. . For now everything works perfectly.
Have a good day!