Hey everyone! I’m working on a project with two contracts: an ERC1155 for NFT minting and an ERC20 for token payments. I’m trying to let users mint NFTs by paying with the ERC20 token, but I’m running into a problem with the transferFrom() function.
The error I’m getting is: brownie.exceptions.VirtualMachineError: revert: ERC20: transfer amount exceeds allowance. I’ve been looking around for solutions, but no luck so far.
Here’s a simplified version of my ERC1155 contract:
i’ve been tinkering with similar stuff and ran into the same headache. have you considered using safeTransferFrom() instead of transferFrom()? it’s a bit safer and might help dodge that pesky allowance issue.
also, curious about your tokenomics - how are you planning to distribute those erc20 tokens? any cool ideas for incentivizing early adopters or community engagement?
oh, and random thought - have you looked into gasless minting? could be a game-changer for user experience. what do you think?
keep us posted on your progress! can’t wait to see what awesome collectibles you’re cooking up
The issue you’re encountering is likely due to insufficient allowance for the ERC1155 contract to spend tokens on behalf of the user. Here’s what you need to do:
Users must approve the ERC1155 contract to spend their tokens before minting.
In your frontend or script, call the approve() function on the ERC20 contract, specifying the ERC1155 contract address and the amount to approve.
After approval, users can call mintCollectible().
Your mintCollectible() function looks correct and doesn’t need to be payable since you’re using ERC20 tokens for payment.
Also, consider implementing a mintPrice variable in your ERC1155 contract to make the token cost configurable. This way, you can easily adjust the price without changing the contract code.
Remember to thoroughly test your contracts and consider getting a security audit before deployment.
yo mate, the problm is probs with allowance. make sure ur users approve the ERC1155 contract to spend their tokens before they try to mint. they gotta call approve() on the ERC20 contract first, then they can mint.
also, u might wanna add a mintPrice variable to ur ERC1155 contract so u can change the price easily. good luck!