I am coding a crowdfunding contract where senders have two options. First, payIn which invokes a transfer to the contract's address. Second, withdraw which invokes a transfer from the contract's address to the sender. However, I cannot transfer to the contract's address because it is not payable
. How can I make the contract payable?
pragma solidity >=0.7.0 <0.9.0;
contract Crowdfunding{
// Crowdfunding settings.
address payable owner;
uint256 goal;
bool isOpen;
// Store the crowd funding values
mapping(address => uint256) public crowd;
constructor(uint256 _goal) {
owner = payable(msg.sender);
isOpen = true;
goal = _goal;
}
function payIn() public fundingIsOpen payable {
address(this).transfer(msg.value);
}
function withdraw() public fundingIsOpen payable {
address(msg.sender).transfer(crowd[msg.sender]);
}
...