I want to allow a user to mint an NFT through my React app to a payable function, but I also want to control the URI and Token ID sent to the contract because we use many different folders on IPFS. Is this possible? If I have a payable function that is also onlyOwner, the owner’s contract pays the minting fee, but I want the user to pay the minting fee. For example, in my React.js minting file
const mintBug = async (e, nextId) => { e.preventDefault(); try { await provider.send("eth_requestAccounts", []); // If I use owner metamask private key owner has to pay // const { REACT_APP_METAMASK_PRIVATE_KEY } = process.env; // const signer = new ethers.Wallet( // REACT_APP_METAMASK_PRIVATE_KEY, // provider // ); // if I use this signer, the user pays const signer = provider?.getSigner(); if (ContractAddress && signer) { const NFTContract = new ethers.Contract( ContractAddress, abi, signer ); // payable amount from contract const value = await NFTContract.MINT_PRICE(); const overrides = { value }; // where userAddress is the address to send it to // and tokenURI is IPFS url await NFTContract.payableMintNFT(userAddress, nextId, tokenURI, overrides); } } catch (err) { console.error(err); } };
And in the contract, for example
function mintNFT(address _toAddress, uint _tokenId, string memory _tokenURI) public payable onlyOwner { _safeMint(_toAddress, _tokenId); _setTokenURI(_tokenId, _tokenURI); _numTokensMinted.increment(); }
Is this even possible? Does anyone have any suggestions for other patterns to follow, like perhaps a payable function to reserve a token ID mapped to an address and then a separate minting function?