Msg in Solidity
What is msg in Solidity?
Msg is a global variable in Solidity which handles everything related to the blockchain in the properties that it holds. Right from the gas fees to the amount of ether required to call any function in the smart contract, all of these values are stored inside the msg global variable and can be accessed by using the dot(.) operator. For example, 'msg. sender' is always the account address from where the function call came from which requires the sender to send some ether to successfully call the function and execute it.
Let's take a look at the different types of msg properties in Solidity:
'msg. sender': It is always the address of the account from where the function call came from.
'msg. gas': Every function call which contains any amount of ether to be sent or deposited in a smart contract requires some gas to call the function successfully, this gas acts as an incentive for the miners. Msg. gas returns the available remaining value of the gas to call the function.
'msg. value': The amount of Ether/Wei deposited or withdrawn by the msg. sender.
'msg. sig': Returns the first 4 bytes of the call data of any function which helps to identify the function which is being called.
As you can see 'msg' is usually used whenever there is some kind of money flow involved in the functions. You should learn to include them in your smart contracts to perform periodic checks to make sure everything is working carefully.
If you have any questions, you can find me on my Twitter and LinkedIn