Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Mojomarv authored Mar 22, 2024
0 parents commit ca9225e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions receiver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

contract receiveETH {
event Log(uint amount, uint gas);

receive() external payable {
emit Log(msg.value, gasleft());
}
}
34 changes: 34 additions & 0 deletions sender.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

contract sendETH {
// 1. pay the contract once its deployed
constructor() payable { }

// 2. directly sends to the contract
receive() external payable { }
// or
// 3.
fallback() external payable { }


// 3 ways to send ETH
// 1. if function call fails the transaction will fail
function sendViaTransfer(address payable to) external payable{
to.transfer(123);
}

// or
// 2. returns boolean value to indicate if the transaction was successful or not
function sendViaSend(address payable to) external payable{
bool sent = to.send(123);
require(sent, "tx failed");
}

// or
// 3. forwards all gas, returns a boolean and data
function sendViaCall(address payable to) external payable{
(bool success, ) = to.call{value: 3000000000000}("");
require(success, "call failed");
}
}

0 comments on commit ca9225e

Please sign in to comment.