I am trying to build an nft marketplace where users buy nft using my own erc20 tokens. I want to eliminate the need for the user to set approval for the marketplace smart contract before they want to buy an nft. Is there any alternate such as setApprovalForAll() function for the erc721 contract?
2 Answers
You can use ERC20Permit extension, so users will approve with signature and transfer tokens in one tx. So in your nft contract buy func will be kind of "swap" of nft for received erc20.
For some ERC20 you can achieve something similar by calling
token.methods.approve(marketPlace, MAX_UINT256)
OpenZeppelin contracts implement that feature.