using openzeppelin-solidity to create crowdsale.
Then I use this statement to Buy Token
MyCrowdsaleInstance.sendTransaction({
from: purchaser[1],
value: web3.utils.toWei("0.5", "ether"),
gas: "220000"
})
And I got the error!
Error: Returned error: VM Exception while processing transaction: revert
at XMLHttpRequest._onHttpResponseEnd (C:\Users\zx\AppData\Roaming\nvm\v10.15.1\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:318:1)
at XMLHttpRequest._setReadyState (C:\Users\zx\AppData\Roaming\nvm\v10.15.1\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:208:1)
at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\zx\AppData\Roaming\nvm\v10.15.1\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request-event-target.js:34:1)
at XMLHttpRequest.request.onreadystatechange (C:\Users\zx\AppData\Roaming\nvm\v10.15.1\node_modules\truffle\build\webpack:\~\web3\~\web3-providers-http\src\index.js:96:1)
at C:\Users\zx\AppData\Roaming\nvm\v10.15.1\node_modules\truffle\build\webpack:\packages\truffle-provider\wrapper.js:112:1
at C:\Users\zx\AppData\Roaming\nvm\v10.15.1\node_modules\truffle\build\webpack:\~\web3-eth\~\web3-core-requestmanager\src\index.js:140:1
at Object.ErrorResponse (C:\Users\zx\AppData\Roaming\nvm\v10.15.1\node_modules\truffle\build\webpack:\~\web3-eth\~\web3-core-helpers\src\errors.js:29:1)
my version:
openzeppelin-solidity: "^2.1.3"
Truffle v5.0.17 (core: 5.0.16)
Solidity v0.5.0 (solc-js)
Node v10.15.1
Web3.js v1.0.0-beta.37
contract code:
// MyToken.sol
pragma solidity ^0.5.0;
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";
contract MyToken is ERC20, ERC20Detailed {
uint public INITIAL_SUPPLY = 10000000000;
constructor(string memory _name, string memory _symbol, uint8 _decimals)
ERC20Detailed(_name, _symbol, _decimals)
public
{
_mint(msg.sender, INITIAL_SUPPLY);
}
}
// MyCrowdsale.sol
pragma solidity ^0.5.0;
import './MyToken.sol';
import "openzeppelin-solidity/contracts/crowdsale/Crowdsale.sol";
contract MyCrowdsale is Crowdsale {
constructor(
uint256 rate, // rate in TKNbits
address payable wallet,
MyToken token
)
Crowdsale(rate, wallet, token)
public
{
}
}
// 2_deploy_token.js
const MyToken = artifacts.require("MyToken");
const MyCrowdsale = artifacts.require("MyCrowdsale");
module.exports = function(deployer, network, accounts) {
const _name = "My Token";
const _symbol = "MTK";
const _decimals = 2;
const rate = 1;
const wallet = accounts[0];
return deployer.then(() => {
return deployer.deploy(MyToken, _name, _symbol, _decimals);
}).then(() => {
return deployer.deploy(
MyCrowdsale,
rate,
wallet,
MyToken.address
);
})
};