I have a nftToken Contract that mints token to msg.sender, then I have a function in a market contract that transfers the nft from owner to market contract. However, I am getting an error that says: ERC721: transfer caller is not owner nor approved.
here is my nftContract (nft) function snippet:
function createToken(string memory tokenURI) public returns (uint) {
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(msg.sender, newItemId);
_setTokenURI(newItemId, tokenURI);
setApprovalForAll(contractAddress, true);
return newItemId;
}
here is my market code (stripeMarket Contract) function snippet:
function createItem(
address nftContract,
uint256 tokenId
) public payable{
address _owner = IERC721(nftContract).ownerOf(tokenId);
IERC721(nftContract).transferFrom(_owner, address(this),tokenId);
IERC721(nftContract).approve(address(this),tokenId);
}
and here I am trying to call it from the frontend with web3:
const getItems=async()=>{
await contracts.nft.methods.createToken("https://i.ytimg.com/vi/nYxGhQYi0s4/maxresdefault.jpg").send({from: accounts[0]});
const owners = await contracts.nft.methods.ownerOf(1).call({from:accounts[0]});
await contracts.stripeMarket.methods.createItem(contracts.nft._address,1).send({from: {owners}});
}
But I am getting the error:
ERC721: transfer caller is not owner nor approved.