We can interact with a contract that we have a sample of. To make it clear, please see how Proxy contract interact with Name contract in this response.
In my scenario, I want to check if the msg.sender is the owner of an NFT. So, I'm trying to interact with any ERC721 contract using the same way instead direct contract call. Like this:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts@4.5.0/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.5.0/token/ERC721/IERC721.sol";
contract Market {
function putOnSale(address _nftContract, uint256 _tokenId, uint256 _price) public payable {
address tokenOwner = ERC721(_nftContract).ownerOf(_tokenId); // ???
require(tokenOwner == msg.sender, 'Only owner...');
// Rest of the code...
}
}
However, I'm getting this error when I call putOnSale method:
transact to Market.putOnSale errored: VM error: revert.
revert
The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.
Can't I interact with another ERC721 contract using this way?
Note: I'm doing this all in Remix IDE JavaScript VM.
Thanks in advance!
putOnSale? If not, that's what flagging your error. You only want to declare a methodpayableif you intend on directly sending Ether (specifically, not any other ERC-20) to it. – Joe Habel Mar 22 '22 at 01:10payableand call without Ether also. @JoeHabel – anileates Mar 22 '22 at 06:13