Уже голову себе всю сломал, что может быть?
Есть два контракта , один токена другой ICO. при обращении к функции buyTokens в которую вводится количество токенов на приобретение, выкидывает ошибку
transact to NEFCrowdsale.buyTokens errored: VM error: revert.
revert The transaction has been reverted to the initial state.
Note: The constructor should be payable if you send value. Debug the transaction to get more information.
pragma solidity ^0.4.11;
import "./SafeMath.sol";
import "./Token.sol";
contract Crowdsale{
using SafeMath for uint;
address public admin;
Token public tokenContract;
uint public tokenPrice;
uint public tokenSold;
event Sell(address _buyer,uint _amount);
function Crowdsale(Token _tokenContract,uint _tokenPrice) public {
admin = msg.sender;
tokenContract = _tokenContract;
tokenPrice = _tokenPrice;
}
function buyTokens(uint256 _numberOfTokens) public payable {
require(msg.value == _numberOfTokens.mul( tokenPrice));
require(tokenContract.balanceOf(this) >= _numberOfTokens);
require(tokenContract.transfer(msg.sender,_numberOfTokens));
tokenSold += _numberOfTokens;
emit Sell(msg.sender,_numberOfTokens);
}
function endSale() public{
require(msg.sender == admin);
require(tokenContract.transfer(admin, tokenContract.balanceOf(this)));
admin.transfer(address(this).balance);
}
}
contract Token{
using SafeMath for uint;
string public name = "Token";
string public symbol = "Token";
string public standard = "Token v1.0";
event Transfer(address indexed _from,address indexed _to,uint _value);
event Approval(address indexed _owner,address indexed _spender,uint _value);
uint public totalSupply;
mapping(address => uint) public balanceOf;
mapping(address => mapping(address=>uint)) public allowance;
function Token(uint _initialSupply) public {
totalSupply = _initialSupply;
balanceOf[msg.sender] = _initialSupply;
}
function transfer(address _to,uint _value) public payable returns(bool success){
require(_to != address(0));
require(_value <= balanceOf[msg.sender]);
balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value);
balanceOf[_to] = balanceOf[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
function approve(address _spender,uint _value) public returns(bool success){
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender,_spender,_value);
return true;
}
function transferFrom(address _from,address _to,uint _value) public returns(bool success){
require(_to != address(0));
require(_value <= balanceOf[_from]);
require(_value <= allowance[_from][msg.sender]);
balanceOf[_from] = balanceOf[_from].sub(_value);
balanceOf[_to] = balanceOf[_to].add(_value);
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
}