Skip to content

Commit

Permalink
Create DAppContract.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Nov 20, 2024
1 parent 6a7a347 commit 3d6835c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions smart-contracts/contracts/DAppContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract DAppContract {
string public name;
address public owner;
mapping(address => uint256) public balances;

event Deposit(address indexed user, uint256 amount);
event Withdraw(address indexed user, uint256 amount);

constructor(string memory _name) {
name = _name;
owner = msg.sender;
}

function deposit() external payable {
require(msg.value > 0, "Deposit amount must be greater than 0");
balances[msg.sender] += msg.value;
emit Deposit(msg.sender, msg.value);
}

function withdraw(uint256 amount) external {
require(balances[msg.sender] >= amount, "Insufficient balance");
balances[msg.sender] -= amount;
payable(msg.sender).transfer(amount);
emit Withdraw(msg.sender, amount);
}

function getBalance() external view returns (uint256) {
return balances[msg.sender];
}
}

0 comments on commit 3d6835c

Please sign in to comment.