I was following a tutorial for a Crowdfunding Smart Contract that acts like Kickstarter from Programtheblockchain, however I'm always getting a MetaMask Error which says "Exception thrown in Contract Code" when trying to send Ether to the Contract. It compiles and deploys just fine, but I can't send Ether to it. Is the code maybe outdated or am I doing something wrong on my end?
pragma solidity ^0.4.19;
contract Crowdfunding {
address owner;
uint256 deadline;
uint256 goal;
mapping(address => uint256) public pledgeOf;
function Crowdfunding(uint256 numberOfDays, uint256 _goal) public {
owner = msg.sender;
deadline = now + (numberOfDays * 1 days);
goal = _goal;
}
function pledge(uint256 amount) public payable {
require(now < deadline); // in the fundraising period
require(msg.value == amount);
pledgeOf[msg.sender] += amount;
}
function claimFunds() public {
require(address(this).balance >= goal); // funding goal met
require(now >= deadline); // in the withdrawal period
require(msg.sender == owner);
msg.sender.transfer(address(this).balance);
}
function getRefund() public {
require(address(this).balance < goal); // funding goal not met
require(now >= deadline); // in the withdrawal period
uint256 amount = pledgeOf[msg.sender];
pledgeOf[msg.sender] = 0;
msg.sender.transfer(amount);
}
}
And my deployment code
var Crowdfunding = artifacts.require("Crowdfunding");
module.exports = function(deployer){
const numberOfDays = 1;
const goal = web3.toWei(10, 'ether');
deployer.deploy(Crowdfunding, numberOfDays, goal);
};