pragma solidity ^0.8.4;
contract Contract {
address payable public owner;
address payable public charity;
constructor(address payable _charity) {
owner = payable(msg.sender);
charity = _charity;
}
receive() external payable { }
function donate() public {
charity.transfer(address(this).balance);
}
function tip() public payable {
owner.transfer(msg.value);
}
}
msg.sender is the person deploys the contract
charity is charity
address(this) is contract address
When I use donate function "msg.value" sent to charity from owner ? But I use address(this).balance in this function. I dont use owner.
I dont understand what is happened when I use tip function ?
donate()
it sends from contract balance into charity address. When you calltip()
you have to set some ETH to be sent to contract, that amount of ETH ismsg.vlue
and it will be sent toowner
address so if you use owner wallet to calltip()
you do not actually do anything