[英]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.