A dynamic contract that allows User to Deposit and withdraw ETH!!
- DEPOSIT
- WITHDRAW
- BALANCE
We will start by understanding how to DEPOSIT into our smart contract, the key thing here is we must first map our address to the sender, after mapping we must create a function.
Notice we signed the address to a Uint(unsigned integer)
We create a function and make a payable because we are sending ETH to the contract, we open the function and make it public since we want anyone to call it
name[msg.sender]+=msg.value;
we said name of sender, whatever value of ETH should be added to Value of sender.
You can compile and test at this point and see what we have done.
we create a new function called withdraw and make it public since we want anybody to call the function
we call an arg and assign it an UINT opening the fucntion we require that whoever deposited can only collect their balance only by saying
require(name[msg.sender]>=_arg,"ERR");
we call tthen minus the amount withdraw from Bal like so, name
[msg.sender]-=_arg;
We create an statement (bool sent,) = msg.sender.call{value: _arg}("sent");
to optimise our contract and allow the contract to be true:
require(sent, "ERR");
Although we have a balance function created for us when we mapped the address to the Balances at the top we need to insert the address to see the balance but atleast create customized balance call
create a new function and then call
return(address(this).balance);