You can create a modifier that costs to call(need to pay an amount to call).
contract Owner {
modifier costs(uint price) {
if (msg.value >= price) {
_;
}
}
}
https://www.tutorialspoint.com/solidity/solidity_function_modifiers.htm
My questions, how do you make the same thing, but require it to be payable not in base currency(eth, bsc,...) but in an ERC20 token?
Thanks in advance!
Tell me if I am wrong:
You want to create a modifier that checks the amount of tokens deposited?
Yeah. But for ERC20 token and not "ether"
You need to use trasnsferFrom and the contract must have enough allowance to take tokens from the user. You could use a dapp with an APPROVE button, like pancake that calls the "approve" function on the token.
Unfortunatly you can't call approve function of an erc20 from a contract passing the user address.
If you do:
token.approve(msg.sender, amount)
The contract will approve itself
This is wrong. The contract will not approve itself.
Did you try it? I think it is as I said but if I am wrong forgive me