I get the error of transacting and gas estimation errored
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import './token.sol';
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract Vendor {
address payable public admin;
address payable private ethFunds = payable(0xF0a0c00Ac9D04d2e0eEF281607836b4AEa130eFa);
Token public token;
uint256 public tokensSold;
int public tokenPriceUSD;
AggregatorV3Interface internal priceFeed;
uint256 public transactionCount;
event Sell(address _buyer, uint256 _amount);
struct Transaction {
address buyer;
uint256 amount;
}
mapping(uint256 => Transaction) public transaction;
constructor(Token _token) {
priceFeed = AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331);
tokenPriceUSD = 50;
token = _token;
admin = payable(msg.sender);
}
function getETHPrice() public view returns(int) {
(, int price, , , ) = priceFeed.latestRoundData();
return (price / 10**8);
}
function facuTokenPriceInETH() public view returns(int) {
int ethPrice = getETHPrice();
return tokenPriceUSD / ethPrice;
}
function buyToken(uint256 _amount) public payable {
//int facuTokenPriceETH = facuTokenPriceInETH();
// Check that the buyer sends the enough ETH
require(int(msg.value) >= tokenPriceUSD * int(_amount));
// Check that the sale contract provides the enough ETH to make this transaction.
require(token.balanceOf(address(this)) >= _amount);
// Make the transaction inside of the require
// transfer returns a boolean value.
require(token.transfer(msg.sender, _amount));
// Transfer the ETH of the buyer to us
ethFunds.transfer(msg.value);
// Increase the amount of tokens sold
tokensSold += _amount;
// Increase the amount of transactions
transaction[transactionCount] = Transaction(msg.sender, _amount);
transactionCount++;
// Emit the Sell event
emit Sell(msg.sender, _amount);
}
function endSale() public {
require(msg.sender == admin);
// Return the tokens that were left inside of the sale contract
uint256 amount = token.balanceOf(address(this));
require(token.transfer(admin, amount));
selfdestruct(payable(admin));
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
contract Token is ERC20 {
constructor() ERC20("CursedToken", "CT") {
_mint(msg.sender, 1000000000 * 10**18);
}
}
When I try to call the function buytokens it creates and transaction but it fails