I’m working on a smart contract that holds NFTs and I want to create a function that lets me, as the owner, send these NFTs to other addresses. I’ve got most of the code written, but I’m running into a problem.
The issue is that when I try to compile this, I get an error saying it can’t find the safeTransferFrom function in IERC721. Am I missing something obvious here? How can I fix this so I can transfer the NFT from my contract to a user’s address?
hey kai29! that’s a pretty cool project you’ve got going there. i’m not an expert, but i’ve dabbled with nfts a bit and might have a suggestion.
have you tried using the regular transferFrom function instead of safeTransferFrom? i remember running into a similar issue and switching to transferFrom fixed it for me. it might look something like this:
The problem likely stems from using an outdated IERC721 interface. To resolve this, you should import the IERC721 interface from OpenZeppelin’s latest contracts. Replace your current import with:
This updated interface includes the safeTransferFrom function. Additionally, ensure you’re using a recent version of OpenZeppelin contracts in your project’s dependencies.
If the issue persists, you might need to explicitly approve the transfer first:
yo kai29, i’ve dealt w/ this before. the issue is probably ur IERC721 interface. u need to import IERC721 from ‘@openzeppelin/contracts/token/ERC721/IERC721.sol’ instead. that should have the safeTransferFrom function. if ur still stuck, lemme kno and i can try to help more!