I am creating a contract for the sale of some tokens already minted.
I have created an interface with the two methods that I use from the Nfts contract. But it seems that the variable does not recognize me as interface but as address.
The error appears to me where I use the interface. As for example in the Tokenbalance function or in BuyTokens TokenContract.safeTransferFrom(owner, msg.sender, tokenId, "");
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
interface TokenInterface {
function balanceOf(address owner) external view returns (uint256 balance);
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) external;
}
/**After deployed remember to allow this contract to manage the NFTs using the function setApprovalForAll
* of the NFTs contract
*
*\The owner of this contract must be the same as that of all the tokens put up for sale
*/
contract Presale is Ownable {
uint256 public limitBuy = 3;
address public _wallet;
uint256 public _tokenPrice = 8000000000000000; //0.8 BNB
TokenInterface TokenContract; // interface of NFT contract.
// Amount of bnbs raised
uint256 public bnbRaised;
/**
* Event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param idToken NFT purchased
*/
event TokenPurchase(
address indexed purchaser,
address indexed beneficiary,
uint256 value,
uint256 idToken
);
constructor (address payable wallet, address addressToken)
{
TokenContract = TokenInterface(addressToken);
_wallet = wallet;
}
function endSold() public onlyOwner() {
payable(_wallet).transfer(address(this).balance);
bnbRaised = 0;
}
function TokenBalance() public returns (uint256) {
uint256 balance = TokenContract.balanceOf(owner);
return balance;
}
function setLimitBuy(uint256 _newLimit) public onlyOwner() {
limitBuy = _newLimit;
}
function getBalanceOfNFTs(address _user) public view returns (uint256){
return TokenContract.balanceOf(_user);
}
/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* @param _beneficiary Address performing the token purchase
*/
function buyTokens(address _beneficiary, uint256 tokenId) public payable {
uint256 balance = getBalanceOfNFTs(_beneficiary);
require(balance <= limitBuy, "You have already purchased the maximum allowed NFTs");
require(msg.value >= _tokenPrice, "value sent needs to be atleast sale price");
TokenContract.safeTransferFrom(owner, msg.sender, tokenId, "");
payable(_beneficiary).transfer(_wallet);
// update state
bnbRaised = bnbRaised.add(msg.value);
emit TokenPurchase(owner, _beneficiary, msg.value, tokenId);
}
}