How can I mint NFTs (ERC721s) and assign the ownership to a smart contract, then transfer them myself as an airdrop to others? I've tried approving myself, but setApprovalForAll
cannot be called by msg.sender
.
So how can I either a) call setApprovalForAll
from the smart contract instead of as myself or b) set approval for myself in some other way so that I can transfer the tokens from the smart contract? I would prefer to avoid making myself the owner and then approving the smart contract as I'd like the airdrop to be more trustless. If I am made the owner I could send the NFTs to whoever.
I would appreciate if anyone could share the right way to do this or let me know if my approach is wrong entirely. Thanks. I've shared a small snippet of code below. Also any other unrelated comments about my code and its style/function would be greatly appreciated, I'm new to Solidity.
// mints 50 NFTs at a time and stores them in this contract
function mintMemories(string memory _tokenURI) public onlyOwner {
require(
memoryCounter < maxMemories,
"Already minted maximum possible memories."
);
for (uint8 i = 0; i < memoryBatchLimit; i++) {
_safeMint(address(this), memoryCounter);
_setTokenURI(memoryCounter, _tokenURI);
// setApprovalForAll(msg.sender, true); ??
memoryCounter++;
}
}