hello,
I deployed successfully my contract with ganache and metamask and everything worked fine.
After that I just changed a little the contract in order to create a player balance (rather than send the money to the winner).
At this point when I migrate the contract i get this error:
Deploying 'coin3'
-----------------
Error: *** Deployment Failed ***
"coin3" hit a require or revert statement somewhere in its constructor. Try:
* Verifying that your constructor params satisfy all require conditions.
* Adding reason strings to your require statements.
at C:\Users\enrico\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\deployer\src\deployment.js:364:1 at processTicksAndRejections (internal/process/task_queues.js:97:5)
at Migration._deploy (C:\Users\enrico\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\migration.js:70:1)
at Migration._load (C:\Users\enrico\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\migration.js:57:1)
at Migration.run (C:\Users\enrico\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\migration.js:167:1)
at Object.runMigrations (C:\Users\enrico\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:148:1)
at Object.runFrom (C:\Users\enrico\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:110:1)
at Object.runAll (C:\Users\enrico\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:114:1)
at Object.run (C:\Users\enrico\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:79:1)
at runMigrations (C:\Users\enrico\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:253:1)
at C:\Users\enrico\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:218:1
truffle(ganache)>
this is the contract (is working fine in remix)
import "./Ownable.sol";
pragma solidity 0.5.16;
contract coin3 is Ownable{
struct player {
uint amount; // amount the player want to bet in ether
uint bet; // what the player want to bet: 0 or 1
string message; // message after flip: WIN or LOSE
uint result; // result of the coin flip return from Provable
uint playerBalance;
}
uint public balance; // updated balance of the contract
uint public minBet; // minimum bet set by the owner
modifier costs(uint cost){
require(msg.value >= cost);
_;
}
// owner send money to the contract at the moment of deployment
constructor() public payable{
require(msg.value >= 9*1000000000000000000);
balance += msg.value;
}
mapping (address => player) private players; // link player to his address
// player set his bet (0 or 1), his bet amount and send that amount to the contract
function setBet(uint amount, uint bet) public payable costs( (players[msg.sender].amount)*1000000000000000000 ){
player memory newPlayer;
newPlayer.amount = amount;
newPlayer.bet = bet;
newPlayer.playerBalance = players[msg.sender].playerBalance;
insertPlayer(newPlayer); // players[msg.sender] = newPlayer
require((players[msg.sender].amount)*1000000000000000000 <= balance/2, "Bet over contract funds");
balance += msg.value;
if(random() == (players[msg.sender].bet)){
balance = balance - (players[msg.sender].amount)*1000000000000000000*2;
players[msg.sender].playerBalance = players[msg.sender].playerBalance + (players[msg.sender].amount)*1000000000000000000*2;
players[msg.sender].message = "WIN";
players[msg.sender].result = random();
}
else{
players[msg.sender].message = "LOOSE";
players[msg.sender].result = random();
}
}
function random() public view returns(uint){
return now % 2;
}
function getResult() public view returns(uint amount, uint bet, string memory message, uint result, uint playerBalance){
address creator = msg.sender;
return (players[creator].amount, players[creator].bet, players[creator].message, players[creator].result, players[creator].playerBalance);
}
// only owner can withdraw money
function withdrawFunds(uint withdraw) public onlyOwner {
balance = balance - withdraw*1000000000000000000;
msg.sender.transfer(withdraw*1000000000000000000);
}
function withdrawFundsPlayer(uint withdraw) public {
require(withdraw<players[msg.sender].playerBalance);
players[msg.sender].playerBalance = players[msg.sender].playerBalance - (withdraw*1000000000000000000);
msg.sender.transfer(withdraw*1000000000000000000);
}
function insertPlayer(player memory newPlayer) private {
address creator = msg.sender;
players[creator] = newPlayer;
}
}