Skip to content

Instantly share code, notes, and snippets.

@ginika-chinonso
Created February 6, 2023 00:25
Show Gist options
  • Save ginika-chinonso/1e48b5bb985277f696db34ef39499554 to your computer and use it in GitHub Desktop.
Save ginika-chinonso/1e48b5bb985277f696db34ef39499554 to your computer and use it in GitHub Desktop.
A smart contract to track the contribution of different people
/*
A fallback function is a function that is called when someone calls a function that is not in the smart contract. The fall back function can also be used to recieve payment made to the contract.
*/
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract EthAjo {
address public owner;
mapping(address => uint) public balances;
constructor() {
owner = msg.sender;
}
function balanceOf(address _address) public view returns (uint) {
return balances[_address];
}
function deposit() public payable returns (bool) {
require(address(msg.sender).balance >= msg.value, "You do not have enough funds");
(bool _success,) = payable(address(this)).call{value: msg.value}("");
require(_success, "Deposit failed");
balances[msg.sender] += msg.value;
return _success;
}
function withdraw(uint _amount) public payable returns (bool) {
require(balances[msg.sender] >= _amount, "You can not withdraw more than you have deposited");
(bool _success,) = payable(address(msg.sender)).call{value: _amount}("");
require(_success, "Withdrawal failed");
balances[msg.sender] -= _amount;
return _success;
}
receive () external payable {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment