pragma solidity ^0.7.2;
pragma solidity ^0.7.2 ;
contract MyContract {
}
pragma solidity ^0.7.2;
contract MyContract{
function depositEth() public payable {
//it will send the ethers to smart contract
}
}
"payable" keyword allows a function to receive ether. This function will receive ethers and send it to smart contract."Public" is a visibility. Any contract and account can call this function if visibility is public.
pragma solidity ^0.7.2;
contract MyContract{
function depositEth() public payable {
//it will send the ethers to smart contract
}
function getContractBal() public view returns (uint){
return address(this).balance;
}
}
getContractBal() function will return the contract balance. "address(this).balance" this line shows the balance of contract. Function is defined as a view because it ensures that it will not modify any state.