i want to mint tokens for an address. For example, suppose I have your wallet address. Now I want to mint 10 ERC20 tokens to your account. The gas fee should be deducted from your account. Now, you are aware that I am going to mint(buy) 10 tokens for you but you don't know when. I don't want you to wait for me that when will I mint tokens on your behalf. So whenever I mint, the minting should be successful and does not require your approval while minting.
So, summarising, I minted(buyed) 10 tokens from your account and the gas fee is deducted from your account and now you will have 10 tokens. Can I write a function like this in solidity.
There are multiple options that you can choose
Option 1
Use a Gas station network. GSN's enable relaying signed transactions and therefore enable paying for the gas in the relay.
Option 2
Mint when the user calls the function, but lock them until you want them to be tradable
Option 3
Write your mint function to mint anything to the contract address. Then, when you want it to be received by the user, transfer them to the user.
Option 4
While the user wants to mint and calls the function, you can request some amount in ether that will approximately cover for the gas that will be used once it is minted. Keep that ether in contract, and once you mint it literally, use that gas.