I’m working on an escrow contract that needs to hold NFTs as deposits. I’ve got the NFT minting part down, but I’m stuck on getting the NFT into the escrow contract.
Here’s what I’ve done so far:
- Created a basic NFT contract that mints tokens
- Minted an NFT to my address
- Tried to approve the escrow contract to handle the NFT
- Attempted to deposit the NFT into the escrow contract
But when I try to deposit, I get an error saying the transfer caller isn’t the owner or approved. I’ve been banging my head against this for hours. What am I missing?
Here’s a simplified version of my escrow contract:
contract SimpleEscrow {
address public nftContract;
uint256 public tokenId;
function holdNFT(address _nftAddress, uint256 _tokenId) public {
nftContract = _nftAddress;
tokenId = _tokenId;
IERC721(nftContract).transferFrom(msg.sender, address(this), tokenId);
}
}
Can anyone spot what I’m doing wrong or suggest a better approach?
hey there MayaPixel55! i’ve been tinkering with nfts too and ran into similar headaches
have you double-checked that your escrow contract is actually approved to handle the nft? sometimes it’s the little things that trip us up!
one thing that helped me was separating the approval and transfer steps. maybe try something like this:
- approve the escrow contract in a separate tx
- then have the escrow contract initiate the transfer
btw, your escrow contract looks good, but maybe add a check to make sure it’s approved? something like:
require(IERC721(_nftAddress).getApproved(_tokenId) == address(this), "not approved");
just a thought! what do you think? have you tried any other approaches?
I’ve encountered this issue before while working on a similar project. The problem likely stems from the approval process. Here’s what you need to do:
First, ensure you’ve properly approved the escrow contract to handle your NFT. This approval must occur in a separate transaction before any transfer attempt.
Next, modify your escrow contract so that it handles the transfer internally. Instead of calling transferFrom directly in the holdNFT function, create a separate deposit function that checks for approval and then proceeds with the transfer:
function depositNFT(address _nftAddress, uint256 _tokenId) public {
require(IERC721(_nftAddress).getApproved(_tokenId) == address(this), 'Not approved');
IERC721(_nftAddress).transferFrom(msg.sender, address(this), _tokenId);
// Additional logic here
}
This ensures that the escrow contract, as the approved entity, initiates the transfer. Always verify the approval before attempting any transfers to avoid errors like the one you encountered.
yo MayaPixel55! i’ve dealt with this before. make sure ur escrow contract is actually approved for the nft. try this:
- approve escrow contract first (separate tx)
- let escrow contract do the transfer
also, add a check in ur contract:
require(IERC721(_nftAddress).getApproved(_tokenId) == address(this), "not approved");
hope this helps! lemme kno if u need more info