openzeppelin-contracts: Token transfer fail
I have your latest version of contracts and almost same example like yours in the Github https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/examples/SampleCrowdsale.sol - I use Ganache for testing on MAC os. And the contract work only when I comment the line
function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal {
//token.transfer(_beneficiary, _tokenAmount);
}
if this is not commented I got a runtime error and revert.
My simple code is as follow:
TOKEN
pragma solidity ^0.4.18;
import 'zeppelin-solidity/contracts/token/ERC20/MintableToken.sol';
/**
* The LeonardianToken contract does this and that...
*/
contract LeonardianToken is MintableToken {
uint256 public constant INITIAL_SUPPLY = 10000;
string public constant name = "Leonardian"; // solium-disable-line uppercase
string public constant symbol = "LEON"; // solium-disable-line uppercase
uint8 public constant decimals = 18; // solium-disable-line uppercase
}
CONTRACT:
pragma solidity ^0.4.18;
import 'zeppelin-solidity/contracts/crowdsale/validation/TimedCrowdsale.sol';
import "zeppelin-solidity/contracts/crowdsale/Crowdsale.sol";
import './LeonardianToken.sol';
contract LeonardianCrowdsale is Crowdsale {
function LeonardianCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, address _wallet, MintableToken _token) public
Crowdsale(_rate, _wallet, _token)
// TimedCrowdsale(_startTime, _endTime)
{
}
}
MIGRATION (without any errors):
var LeonardianCrowdsale = artifacts.require("./LeonardianCrowdsale.sol");
var LeonardianToken = artifacts.require("./LeonardianToken.sol");
module.exports = function(deployer) {
deployer.deploy(LeonardianToken).then(function () {
const startTime = Math.round((new Date(Date.now() - 86400000).getTime())/1000); // Yesterday
const endTime = Math.round((new Date().getTime() + (86400000 * 20))/1000); // Today + 20 days
var exchangeRate = 1; // 1 LEON = 0.0025 ETH or 1 ETH = 400 LEON
deployer.deploy(LeonardianCrowdsale,
startTime,
endTime,
exchangeRate,
"0x627306090abaB3A6e1400e9345bC60c78a8BEf57", // Replace this wallet address with the last one (10th account) from Ganache UI. This will be treated as the beneficiary address.
LeonardianToken.address
);
});
};
Can you help me what, I`m doing wrong?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (5 by maintainers)
The main issue was that by tying the token creation to the crowdsales:
and by separating the concerns we’re now much more composable (the crowdsale only cares about how to issue the token; either by minting, transferring, or some other custom method) and the token can be anything that conforms to the correct interface.
I got help in Open Zeppelin slack! The problem was with crowdsale contract. I updated my github repo.
@pjworrall the crowdsale is not the owner of the mintable token; it must be the owner in order to mint tokens
Is the explanation here that passing in the token contract from the truffle migration js doesn’t work? Because the contracts/examples/SimpleCrowdsale.js example led me to a pattern where the Token contract was create and deployed by truffle in the migration js and an argument was defined in the SimpleCrowdsale constructor to receive its Address at deployment time with the other arguments like rate, start time and end time etc.
so
The example migration is something as follow: