I'm creating an NFT contract which can be bought with my token, when calling the approve function of the token to be able to buy the nft using the tokens, the msg.sender in this case is the nft contract itself and not the user who approves the transaction. How could I solve this?
NFT function:
function createRandomGoblin () public payable {
uint256 price = getCreateGoblinPrice() * 10 ** 18; // Wei price
require(blueGem.balanceOf(msg.sender) >= price);
require(blueGem.approve(address(this), price), "Failed to approve token transfer");
//address a = blueGem.returnaddress();
require(blueGem.transferFrom(msg.sender, address(this), price));
_createGoblin(msg.sender);
}
Token function:
function approve(address spender, uint256 amount) public notPaused override returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
I'm using the IBEP20 standard for the token.
I have thought of creating a function that receives the user's address as a parameter and uses the msg.sender (nft contract) as sender. But this opens a code sploit to anyone being able to create their approve.
function approveNFTContract(address owner, uint amount) public notPaused returns (bool){
_approve(owner, msg.sender, amount);
return true;
}