title: How to transfer an ERC721 token
body: <p>I'm trying to transfer an ERC721 token, but I'm getting the error <code>ERC721: transfer caller is not owner nor approved</code> for the <code>transferToken</code> method.</p>
  <p><strong>Main.sol</strong></p>
  <pre><code>import &quot;./ERC721.sol&quot;;
  import &quot;./Counters.sol&quot;;
  
  contract Main is ERC721 {
      using Counters for Counters.Counter;
      Counters.Counter internal _tokenIds;
      address payable internal admin; 
  
      constructor() ERC721(&quot;MyToken&quot;, &quot;TOKEN&quot;) {
          admin = payable(msg.sender);
      }
  }
  </code></pre>
  <p><strong>Auction.sol</strong></p>
  <pre><code>import &quot;./Main.sol&quot;;
  
  contract Auction is Main {
      struct AuctionInfo {
          uint256 tokenId;
          address highestBidder;
          uint highestBid;
      }
  
      mapping(string =&gt; AuctionInfo) private _auctionInfo;
  
      function createAuction(string memory id) public {
          _tokenIds.increment();
  
          uint256 newTokenId = _tokenIds.current();
          _mint(msg.sender, newTokenId);
          
          _auctionInfo[id].tokenId = newTokenId;
      }
  
      function transferToken(string memory id) public {
          require(msg.sender == _auctionInfo[id].highestBidder, &quot;You are not the highest bidder&quot;);
  
          safeTransferFrom(address(this), _auctionInfo[id].highestBidder, _auctionInfo[id].tokenId);
      }
  
      // other methods...
  }
  </code></pre>
  <p>The minting contract is <code>this</code> and the owner of the token is the <code>msg.sender</code> of the minting method if I'm not mistaken. Am I to use the <code>approve</code> (or <code>setApprovalForAll</code>) for <code>this</code> each time before transferring? I've tried <code>this</code>, <code>payable(this)</code>, and <code>address(this)</code> for the <code>safeTransferFrom</code> method, but none seem to be working.</p>
  <p>For example, I tried the following, but get the same revert message:</p>
  <pre><code> approve(address(this), _auctionInfo[id].tokenId);
   this.safeTransferFrom(address(this), _auctionInfo[id].highestBidder, _auctionInfo[id].tokenId);
  </code></pre>