Payable
A function cannot receive Ether, unless marked as payable .
payable .// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.1;
contract SendMoneyExample {
uint public balanceReceived;
function receiveMoney() public payable {
balancedReceived += msg.value; //msg: global always-existing object
}
function getBalance() public view returns(uint) {
return address(this).balance
}
}
Last updated