Quiz Entry - updated: 2026.07.30
What does the payable keyword do, and what are msg.sender and msg.value?
payable marks a function (or address) as able to receive the chain's native currency. msg.sender is the address that called the function; msg.value is how much currency (in wei) was sent with the call.
function fund() public payable {
// msg.sender = caller's address
// msg.value = wei sent along with this call
}
Without payable, a function rejects any attached value — Remix shows payable functions as red buttons. Contracts, like wallets, have addresses and can therefore hold a balance. msg.sender and msg.value are globally available inside any function:
msg.sender— the account that invoked this function (e.g. to record who funded).msg.value— the amount of native token sent in the same transaction (in wei).
To later send funds out to msg.sender, you must cast it to a payable address: payable(msg.sender).
Go deeper:
Solidity docs: special variables and functions —
msg.sender,msg.value, and the block/transaction globals.