1

I have some ERC721 NFTs in my wallet minted in A smart contract.
I want to transfer that NFTs to another wallet using my smart contract.
But I am getting error like: "ERC721: approve caller is not owner nor approved for all"

This is my code:

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract Coller is ERC721Enumerable, Ownable {

    address public  deadAddress = 0x000000000000000000000000000000000000dEaD;
    constructor(
        
    ) ERC721("Coller Token", "Coller") {

    }
 
    function approveAndTransfer(ERC721 nft, uint256 _tokenId) public {
        nft.approve(deadAddress, _tokenId);
        nft.transferFrom(msg.sender, deadAddress,_tokenId);
    }
}

Who can fix this error and help me?

9
  • you cant approve and transferFrom in the same transaction. In your method -> the first line will approve the deadAddress to transfer tokenId onbehalf your contract . The Second line is trying to transfer the token from msg.sender to deadAddress and is triggered by the contract which has no permission to do that
    – Majd TL
    Sep 30, 2021 at 6:42
  • the msg.sender need to approve the token to the contract. and then your method need only to call transferfrom
    – Majd TL
    Sep 30, 2021 at 6:43
  • Dear Majd, I didn't understand what you say. so I hope that you send some code for me.
    – Abe Yusei
    Sep 30, 2021 at 9:56
  • "I have some ERC721 NFTs in my wallet minted in A smart contract." ? who developed that smart contract and how you got the NFT? //// //// /////"I want to transfer that NFT to another wallet using my smart contract." ? why using your contract, and not just transfer the NFT using the original contract?
    – Majd TL
    Sep 30, 2021 at 10:46
  • I minted that NFT in A smart contract and got it. currently, I got some idea. But to complete the idea, I have to transfer my NFT to another wallet using my smart contract. Can you help me? I think you are expert smart contract developer, but I am a beginner. So if you can help me, please share the code to complete my idea.
    – Abe Yusei
    Sep 30, 2021 at 11:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.