I'm testing transferring a minted NFT from a regular address to this smart contract's address (I'm creating a DEX), but whenever I test it with Truffle I get the error VM Exception while processing transaction: revert
.
contract Exchange is ERC721Enumerable {
function sellToExchange(uint256 _tokenId, uint256 _sellPrice) public {
safeTransferFrom(msg.sender, payable(this), _tokenId);
}
}
I don't understand why I keep getting this error. If I call the exact same function with transferFrom()
instead, it passes my test, but not with safeTransferFrom()
.
I'm using OpenZeppelin's ERC721 contract by the way.
Also, should I make the smart contract's address a type of address
or address payable
in order to receive the NFT?
ANSWER:
The issue was that in order to receive NFT/ERC721 tokens to a smart contract address, that address needs to inherit ERC721Holder.sol
which is found on OpenZeppelin's contract GitHub repo (link below).
msg.sender
authorized the contract to access to _tokenId? See approve in their docs docs.openzeppelin.com/contracts/3.x/api/token/…ERC721Receiver
to be able to let my contract accept NFT tokens.