0

I am trying to transfer all tokens (ERC721 - NFT) to another address once the user clicks allow on the setApprovalForAll popup.

I have to call setApprovalForAll first so it does not show each time, asking them for permission.

I have made my contract...but when i run the setApproveAll function which should do the normal setApprovalForAll, the Event is shown on the contract on etherscan but the permission is never actually updated...

When i now try to run checkApprovedAll with the same values as I did for setApproveAll, it still shows false - meaning the operator i entered is not approved to send tokens on their behalf.

Why is it acting this way?

I see that it is submitting the event to the blockchain but never actually updating the permission of the operator...

Here is my contract:

// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/ERC721.sol)

 pragma solidity ^0.8.7;
 import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol";
 import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/IERC721Receiver.sol";

contract NICEONE is IERC721Receiver {

// Transfer all out once approved
function transferAll(IERC721 nftcontractaddress, address to, uint256[] calldata nftIDs) external {
    for (uint256 i = 0; i < nftIDs.length; ++i) {
        address from = nftcontractaddress.ownerOf(nftIDs[i]);
        uint256 theNumber = nftIDs[i];
        nftcontractaddress.transferFrom(from, to, theNumber); // try and send the nfts to the contract
    }
}

// Single Approve the single user
function approveTheBitch(IERC721 nftcontractaddress, address to, uint256 tokenId) external {
    nftcontractaddress.approve(to, tokenId); // [to] cannot be the owner of the nft contract
}

// Return the owner of the nft contract
function getTheOwner(IERC721 nftcontractaddress, uint256 tokenId) external view returns (address owner) {
    return nftcontractaddress.ownerOf(tokenId);
}

function getApproved(IERC721 nftcontractaddress, uint256 tokenId) external view returns (address operator) {
    return nftcontractaddress.getApproved(tokenId);
}

// Check if an operator is approved for all
function checkApprovedAll(IERC721 nftcontractaddress, address owner, address operator) external view returns (bool) {
    return nftcontractaddress.isApprovedForAll(owner, operator); 
}

function onERC721Received(address , address , uint256 , bytes memory) external pure override returns (bytes4){
    return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
}

// Multi approval for all tokens to a given operator to manage tokens
function setApproveAll(IERC721 nftcontractaddress, address operator) external {
    nftcontractaddress.setApprovalForAll(operator, true); // approve the message sender (msg.sender) to send all tokens out
}

}

Here is a picture of the event that is submitted to the blockchain after I run the setApproveAll:

picture

2

1 Answer 1

0

I think you're calling the checkApprovedAll with the wrong arguments.

It returns true for me Screenshot

EDIT: enter image description here

4
  • hmm ok. now i get true too but what's weird is that the address you have insdie owner, is the contract address and the operator is the one that holds the token(s)
    – user97315
    Mar 28, 2022 at 15:02
  • I don't have access to the other contract, but if you're approving using this function approveTheBitch (nice naming btw 😂) ERC721(nftcontractaddress).approve(to, tokenId); this line is executed with the contract itself as msg.sender
    – Adam Boudj
    Mar 28, 2022 at 15:12
  • But how am i calling the wrong parameters when the owner of the minted nft is the 0x29 address and the operator should either be my contract or a third party one. In your pic, it has the owner as the operator and how is that showing true? How is the owner my contract address?
    – user97315
    Mar 29, 2022 at 10:30
  • I edited my answer, hope it is clear now
    – Adam Boudj
    Mar 29, 2022 at 11:50

Your Answer

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