1

I initially transferred some ether into the smart contract when deployed and in one of the function I should be transferring ether to the address of the msg.sender. Help me out if you can!

qwak
  • 11
  • 1

1 Answers1

1

Here is a simple example of a function by which someone can get a specific amount of wei from a contract contaning this function.

I tried to keep it as simple as possible. Therefore it is unsafe to use, as this function can be called by anyone to withdraw ETH from the contract. Please use it only for learning purposes and don't implement it on any production contracts.

function withdraw(uint amount) public {
(bool sent, ) = msg.sender.call{value: amount}("");
require(sent, "Failed to send Ether");


}

Sky
  • 2,282
  • 2
  • 7
  • 26