I am trying to create a token contract and the token sale contract.
Token Contract : ERC20 token is ready and it is flawless TokenSale Contract : I have passed the "Token"" contract to "TokenSale" and created it. It has the function "pushTokens". It just pushes the coins from owners address to beneficiary address
When I tested in remix using "JavaScript VM" environment, I have the issue in the below location where I transfer the created ERC20 tokens, it fails. I am not able to understand the issue.
I have changed the ownership to "TokenSale" Contract
Note : I don't receive the ETH from user while they using the "TokenSale" contract
Source code of contracts (Flattened file)
Token : https://textuploader.com/1e2jg
TokenSale : https://textuploader.com/1e2jx
Relevant code from Token Contract
library SafeERC20 {
using SafeMath for uint256;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
require(token.transfer(to, value)); **--------- Issue Line -------**
}
Relevant code from TokenSale Contract
contract TokenSale is Crowdsale{
event CrowdsaleFinalized();
constructor(
ERC20Mintable token
)
public
Crowdsale(token)
{
require(address(token) != address(0),"Token is not an address");
}
}
contract Crowdsale is ReentrancyGuard {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// The token being sold
IERC20 private _token;
// Amount of wei raised
uint256 private _releasedToken;
event TokensPurchased(address indexed purchaser, address indexed beneficiary, uint256 amountOfTokens);
constructor (IERC20 token) public {
require(address(token) != address(0));
_token = token;
}
function () external payable {
}
function token() public view returns (IERC20) {
return _token;
}
function releasedToken() public view returns (uint256) {
return _releasedToken;
}
function pushTokens(address payable beneficiary,uint256 rate,uint256 amountOfTokens) public nonReentrant payable {
_preValidatePurchase(beneficiary, rate, amountOfTokens);
// update state
_releasedToken = _releasedToken.add(amountOfTokens);
_processPurchase(beneficiary, amountOfTokens);
emit TokensPurchased(msg.sender, beneficiary, amountOfTokens);
_updatePurchasingState(beneficiary, amountOfTokens);
_postValidatePurchase(beneficiary, amountOfTokens);
}
function _preValidatePurchase(address beneficiary, uint256 rate, uint256 amountOfTokens) internal view {
require(beneficiary != address(0));
require(rate > 0);
require(amountOfTokens > 0);
}
function _postValidatePurchase(address beneficiary, uint256 amountOfTokens) internal view {
// optional override
}
function _deliverTokens(address beneficiary, uint256 tokenAmount) internal {
_token.safeTransfer(beneficiary, tokenAmount);
}
function _processPurchase(address beneficiary, uint256 tokenAmount) internal {
_deliverTokens(beneficiary, tokenAmount);
}
function _updatePurchasingState(address beneficiary, uint256 amountOfTokens) internal {
// optional override
}
}
contract TokenSale is Crowdsale{
event CrowdsaleFinalized();
constructor(
ERC20Mintable token
)
public
Crowdsale(token)
{
require(address(token) != address(0),"Token is not an address");
}
}
Error Location
Error
Deploy / Run