I'm building my dApp by modifying the pet-shop example, however, I got stuck at the migration step. 1_initial_migration.js
runs successfully but 2_deploy_contracts.js
gives me the following error despite the fact I modified it accordingly.
I've read all the Migration Documentation and gone through a number of related post but I'm still having a hard time understanding how it relates to my project.
... 0x48c02fda96b9e71d1b219e4b09876181027c60aa2589c9ccd7f46f2970e4f34b Error encountered, bailing. Network state unknown. Review successful transactions manually. Error: VM Exception while processing transaction: invalid opcode at Object.InvalidResponse (C:\Users\charles.fried\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:43303:16) at C:\Users\charles.fried\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:331156:36 at C:\Users\charles.fried\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:175492:11 at C:\Users\charles.fried\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:314196:9 at XMLHttpRequest.request.onreadystatechange (C:\Users\charles.fried\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:329855:7) at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\charles.fried\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:70159:18) at XMLHttpRequest._setReadyState (C:\Users\charles.fried\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:70449:12) at XMLHttpRequest._onHttpResponseEnd (C:\Users\charles.fried\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:70604:12) at IncomingMessage. (C:\Users\charles.fried\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:70564:24) at emitNone (events.js:91:20)
2_deploy_contracts.js:
var Plant = artifacts.require("Plant");
module.exports = function(deployer) {
deployer.deploy(Plant);
};
Plant.sol:
pragma solidity ^0.4.18;
contract Plant {
address public creator;
// initial Variables
uint public number_of_leaves;
uint public remaining_leaves = 0; // has to start on 1 otherwise it cancels price calculation
uint public initial_coins;
uint public total_supply;
uint public finney_balance; // 1 Ether is 1,000 finney - see this converter -> https://converter.murkin.me/
uint public plant_price = 60; // Price is in Finney $20 if approx 60 Finney
uint public number_of_plants;
// Modififer to check if there's enough money for a new plant without wasting gas
modifier onlyIfEnoughMoney() {
require(finney_balance > plant_price);
_;
}
// only_creator can update price
modifier onlyCreator() {
require(msg.sender == creator);
_;
}
// you need to send some money to initialise the contract
modifier enoughToInitialise() {
require(msg.value > 0);
_;
}
function Plant(uint _number_of_leaves, uint _initial_coins) public payable enoughToInitialise {
number_of_leaves = _number_of_leaves;
remaining_leaves = number_of_leaves;
initial_coins = _initial_coins;
total_supply = initial_coins;
finney_balance = msg.value/1000000000000000;
creator = msg.sender;
number_of_plants ++;
depositedFunds(msg.value, finney_balance);
}
function buy_new_plant() private onlyIfEnoughMoney {
uint number_plants_to_buy = finney_balance / plant_price;
total_supply += (initial_coins*number_plants_to_buy);
finney_balance -= (plant_price*number_plants_to_buy);
number_of_plants += number_plants_to_buy;
plantWasPurchased(finney_balance, total_supply, number_of_plants);
}
function () payable public {
finney_balance += msg.value/1000000000000000;
buy_new_plant();
depositedFunds(msg.value, finney_balance);
}
function terminate() private onlyCreator{
selfdestruct(creator);
}
function leafPicked(uint numPicked) public onlyCreator returns (uint){
require(numPicked < remaining_leaves);
remaining_leaves -= numPicked;
leafWasPicked(remaining_leaves, numPicked);
}
event leafWasPicked(uint leavesLeft, uint numberTaken);
event plantWasPurchased(uint newBalance, uint newTotalSupply, uint newPlantNumber); // Event
event depositedFunds(uint amount, uint newBalance); // Event
}