Loading...
In this smartbook, we'll discuss how to deposit some ether in our contract address.
we use some events and create two functions one is for the deposit amount and the other is check balance.
Define the event name Deposit inside they've three-parameter:
event Deposit(address payable from, uint amount, uint balance);
Create a function name deposit and call this event inside this function. With the help of " emit " keyword.
function deposit() public payable{
emit Deposit(msg.sender, msg.value, address(this).balance);
}
One more function creation will define to check the balance.
function getBalance() public view returns(uint){
return address(this).balance;
}
pragma solidity >=0.4.5 <0.9.0;
contract MyContract{
event Deposit(address payable from, uint amount, uint balance);
function deposit() public payable{
emit Deposit(msg.sender, msg.value, address(this).balance);
}
function getBalance() public view returns(uint){
return address(this).balance;
}
}