I'm following a LinkedIn course on Solidity and creating a simple contract. Code below:
I'm new to solidity so I'm not sure exactly where I'm going wrong but I get the following error:
Transact to Inheritance.Died errored: VM error: revert. The Transaction has been reverted to initial state. The constructor should be payable if you send value.
I have the word payable denoted in my constructor should not sure what is going on. Programming errors can sometimes mean a million things.
Note: I'm compiling and running in remix IDE
//import solidity
pragma solidity ^0.5.1;
contract Inheritance {
address owner;
bool deceased;
uint money;
constructor() public payable {
owner = msg.sender;
money = msg.value;
deceased = false;
}
modifier oneOwner {
require (msg.sender == owner);
_;
}
modifier isDeceased {
require (deceased = true);
_;
}
// setup an array of addresses and call the array wallets
address payable[] wallets;
//
mapping (address => uint) inheritance;
// needs the modifier oneOwner to run
// function to setup the wallet
function setup(address payable _wallet, uint _inheritance) public oneOwner {
wallets.push(_wallet);
inheritance[_wallet] = _inheritance;
}
function moneyPaid() private isDeceased {
for (uint i=0; 0<wallets.length; i++) {
wallets[i].transfer(inheritance[wallets[i]]);
}
}
function died() public oneOwner {
deceased = true;
moneyPaid();
}
}
died
, but the contract didn't have a sufficient ether balance to pay out all the inheritances, so one of thetransfer
calls failed.