简体   繁体   English

检查所有者是 msg.sender,但仍然给出 ERC721:transfer caller is not owner nor approved

[英]Check owner is msg.sender, but still gives ERC721: transfer caller is not owner nor approved

I can't seem to figure out what is wrong, even looking at other questions posted.我似乎无法弄清楚出了什么问题,即使查看发布的其他问题也是如此。 The token should be holding the nft代币应该持有 nft

In the NFT contract,在 NFT 合约中,

function NFTMe(string memory tokenUR) public returns (uint256) {
        uint256 newTokenId = _tokenIds.current();
        _mint(msg.sender, newTokenId);
        _setTokenURI(newTokenId, tokenUR);
        // setApprovalForAll(msg.sender, true); <-- this will give me reverted with reason string 'ERC721: approve to caller'
        _tokenIds.increment();
        return newId ;
    }

I have another function to see who is the owner:我还有一个function,看看谁是主人:

function getOwner(uint256 tokenId) public view returns(address) {
        address owner = ERC721.ownerOf(tokenId);
        return owner;
    }

When I deploy, it says currentOwner is the owner who minted it.当我部署时,它说 currentOwner 是创建它的所有者。

In the token,在令牌中,

constructor( string memory _name, string memory _symbol, address nftAddr) ERC20(_name, _symbol) {
nft = IERC721(nftAddr);
}
function transfer() public {
    // 'ERC721: transfer caller is not owner nor approved'
    nft.transferFrom(msg.sender, address(this), nftId); 
 }
// 'ERC721: transfer caller is not owner nor approved'
nft.transferFrom(msg.sender, address(this), nftId); 

In this case, the "transfer caller" is your token contract.在这种情况下,“转账调用者”是您的代token合约。 Which is not the token owner, not approved by the user (the token owner) to transfer the token.不是token owner,未经用户(token owner)同意转让token。

The easiest solution is to make the token contract automatically approved by the user from within the NFTMe() function in the NFT contract:最简单的解决方案是让用户从NFT合约中的NFTMe() function 中自动批准代token合约:

_approve(tokenContractAddress, newTokenId);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ERC721:转接呼叫者既不是所有者也不是批准的 - ERC721: transfer caller is not owner nor approved 此函数以原因字符串“ERC721:转移调用者不是所有者也不是批准”恢复 - This function reverted with reason string 'ERC721: transfer caller is not owner nor approved' 多边形区块链上 MetaMask 的内部 JSON-RPC 错误。 `ERC721:转接呼叫者既不是所有者也不是批准的。` - Internal JSON-RPC error with MetaMask on Polygon Blockchain. `ERC721: transfer caller is not owner nor approved.` 错误:处理事务时出现 VM 异常:已恢复,原因字符串为“ERC721:转移呼叫者不是所有者也未获批准” - Error: VM Exception while processing transaction: reverted with reason string 'ERC721: transfer caller is not owner nor approved' 将 ERC721 从所有者转让给买家 - Transfer ERC721 from owner to buyer msg.sender不等于所有者 - msg.sender is not equal to owner 在 ERC721 上按所有者列出所有令牌 ID - list all token IDs by owner at ERC721 如何向以太币令牌所有者发送以太币? - How to send ether to erc721 token owner? require(msg.sender == owner(), 'not owner') 抛出异常,尽管在事件中检查 msg.sender 等于 owner() - require(msg.sender == owner(), 'not owner') throwing exception although msg.sender equals owner() when inspected in event erc721 NFT的锁转移 - Lock transfer of erc721 NFT
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM