Skip to main content

I am trying to call ERC721 from another smart contract, while calling function approveAndTransfer ,I am getting "ERC721: transfer caller is not owner nor approved", not sure reason behind it,

As require(nft.ownerOf(_tokenId) == msg.sender, "NOT OWNER FUCK OFFF"OWNER"); is working as expected and not throwing any error, but source of error is _tranfer function which gets called from nft.safeTransferFrom(msg.sender, _to,_tokenId);

not sure what mistake I am making. I have NFT in my wallet, but I am not owner of external smart contract.

    // SPDX-License-Identifier: MIT
pragma solidity 0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/IERC721.sol";

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

contract Tat is IERC721Receiver {
    
constructor() public {}


function approveAndTransfer(IERC721 nft, uint256 _tokenId, address _from, address _to) public {
    require(nft.ownerOf(_tokenId) == msg.sender, "NOT OWNER FUCK OFFF"OWNER");
    nft.isApprovedForAll(_from, address(this));
    nft.safeTransferFrom(msg.sender, _to,_tokenId);
}

function ownerOf(IERC721 nft, uint256 tokenId) external view returns (address owner) {
    return nft.ownerOf(tokenId);
}


function test() public view returns(address sc,address own){
    return (address(this),msg.sender);
}


function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes memory _data) public override returns(bytes4) {
       return 0x150b7a02;
 }

}

Thanks in advance.

I am trying to call ERC721 from another smart contract, while calling function approveAndTransfer ,I am getting "ERC721: transfer caller is not owner nor approved", not sure reason behind it,

As require(nft.ownerOf(_tokenId) == msg.sender, "NOT OWNER FUCK OFFF"); is working as expected and not throwing any error, but source of error is _tranfer function which gets called from nft.safeTransferFrom(msg.sender, _to,_tokenId);

not sure what mistake I am making. I have NFT in my wallet, but I am not owner of external smart contract.

    // SPDX-License-Identifier: MIT
pragma solidity 0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/IERC721.sol";

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

contract Tat is IERC721Receiver {
    
constructor() public {}


function approveAndTransfer(IERC721 nft, uint256 _tokenId, address _from, address _to) public {
    require(nft.ownerOf(_tokenId) == msg.sender, "NOT OWNER FUCK OFFF");
    nft.isApprovedForAll(_from, address(this));
    nft.safeTransferFrom(msg.sender, _to,_tokenId);
}

function ownerOf(IERC721 nft, uint256 tokenId) external view returns (address owner) {
    return nft.ownerOf(tokenId);
}


function test() public view returns(address sc,address own){
    return (address(this),msg.sender);
}


function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes memory _data) public override returns(bytes4) {
       return 0x150b7a02;
 }

}

Thanks in advance.

I am trying to call ERC721 from another smart contract, while calling function approveAndTransfer ,I am getting "ERC721: transfer caller is not owner nor approved", not sure reason behind it,

As require(nft.ownerOf(_tokenId) == msg.sender, "NOT OWNER"); is working as expected and not throwing any error, but source of error is _tranfer function which gets called from nft.safeTransferFrom(msg.sender, _to,_tokenId);

not sure what mistake I am making. I have NFT in my wallet, but I am not owner of external smart contract.

    // SPDX-License-Identifier: MIT
pragma solidity 0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/IERC721.sol";

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

contract Tat is IERC721Receiver {
    
constructor() public {}


function approveAndTransfer(IERC721 nft, uint256 _tokenId, address _from, address _to) public {
    require(nft.ownerOf(_tokenId) == msg.sender, "NOT OWNER");
    nft.isApprovedForAll(_from, address(this));
    nft.safeTransferFrom(msg.sender, _to,_tokenId);
}

function ownerOf(IERC721 nft, uint256 tokenId) external view returns (address owner) {
    return nft.ownerOf(tokenId);
}


function test() public view returns(address sc,address own){
    return (address(this),msg.sender);
}


function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes memory _data) public override returns(bytes4) {
       return 0x150b7a02;
 }

}

Thanks in advance.

Source Link
Seth x
  • 41
  • 1
  • 2

approve + safeTransferFrom ERC721 from existing smart contract

I am trying to call ERC721 from another smart contract, while calling function approveAndTransfer ,I am getting "ERC721: transfer caller is not owner nor approved", not sure reason behind it,

As require(nft.ownerOf(_tokenId) == msg.sender, "NOT OWNER FUCK OFFF"); is working as expected and not throwing any error, but source of error is _tranfer function which gets called from nft.safeTransferFrom(msg.sender, _to,_tokenId);

not sure what mistake I am making. I have NFT in my wallet, but I am not owner of external smart contract.

    // SPDX-License-Identifier: MIT
pragma solidity 0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/IERC721.sol";

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

contract Tat is IERC721Receiver {
    
constructor() public {}


function approveAndTransfer(IERC721 nft, uint256 _tokenId, address _from, address _to) public {
    require(nft.ownerOf(_tokenId) == msg.sender, "NOT OWNER FUCK OFFF");
    nft.isApprovedForAll(_from, address(this));
    nft.safeTransferFrom(msg.sender, _to,_tokenId);
}

function ownerOf(IERC721 nft, uint256 tokenId) external view returns (address owner) {
    return nft.ownerOf(tokenId);
}


function test() public view returns(address sc,address own){
    return (address(this),msg.sender);
}


function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes memory _data) public override returns(bytes4) {
       return 0x150b7a02;
 }

}

Thanks in advance.