Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhance PaymentReceiver contract security and transparency #1538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,27 @@ In this example, the fallback function is marked as external and payable, which

```solidity
contract PaymentReceiver {
address payable owner;

address payable public owner;

event EtherWithdrawn(address indexed to, uint256 amount);

constructor() payable {
owner = payable(msg.sender); // Convert msg.sender to payable
owner = payable(msg.sender);
}

function receiveEther() public payable {
// This function can receive Ether
}

function withdrawEther() public {
owner.transfer(address(this).balance); // Send Ether to owner
require(msg.sender == owner, "Only owner can withdraw");
uint256 balance = address(this).balance;
require(balance > 0, "No ether to withdraw");

(bool success, ) = owner.call{value: balance}("");
require(success, "Transfer failed");

emit EtherWithdrawn(owner, balance);
}
}
```
Expand Down
Loading