The code example is https://github.com/facuspagnuolo/ethereum-spiking/tree/master/5-token-sale-contract
The related files are:
1. contracts\MyToken.sol
contract MyToken is BasicToken, Ownable {
uint256 public constant INITIAL_SUPPLY = 10000;
function MyToken() {
totalSupply = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
Transfer(0x0, msg.sender, INITIAL_SUPPLY);
}
}
2. contracts\TokenSale.sol
contract TokenSale is Ownable {
MyToken public token;
uint256 public priceInWei;
bool public tokenSaleClosed;
event TokenPurchase(address buyer, address seller, uint256 price, uint256 amount);
function TokenSale(MyToken _token, uint256 _price) public {
if (_price < 0) return;
token = _token;
priceInWei = _price;
tokenSaleClosed = false;
}
}
3. migrations\2_deploy_contracts.js
const MyToken = artifacts.require("./MyToken.sol");
const TokenSale = artifacts.require("./TokenSale.sol");
module.exports = function(deployer) {
deployer.deploy(MyToken);
deployer.deploy(TokenSale);
};
when I deploy it by truffle and testrpc ($ truffle migrate), it fails as the following:
Using network 'development'.
Running migration: 2_deploy_contracts.js Deploying MyToken... ... 0x289577d078c8fbc61585127ac123dbef43aa711529bf079c4fd400206c65e0de MyToken: 0x33ddda65330e75e45d3d2e4e270457915883c2fc Deploying TokenSale... Error encountered, bailing. Network state unknown. Review successful transactions manually. Error: TokenSale contract constructor expected 2 arguments, received 0 at C:\Users\zklin\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\truffle-contract\contract.js:390:1 at new Promise () at C:\Users\zklin\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\truffle-contract\contract.js:374:1 at at process._tickCallback (internal/process/next_tick.js:188:7)