## Some Global Variable and Call data (Beginer friendly explanation)
### `msg` in Solidity
In **Solidity**, `msg` is a special **global variable** (part of the transaction context) that gives information about the current call/transaction.
---
### `msg.data`
* This is the **complete calldata** (raw input data) that was sent with the transaction.
* It’s in **bytes** form.
* It contains:
* The **function selector** (first 4 bytes → tells which function to call).
* The **encoded arguments** (the rest of the bytes).
Example:
```solidity
function store(uint256 x) public {
// nothing here, but msg.data will contain
// the function selector + encoded 'x'
}
```
If you call `store(5)`, then:
* `msg.data` = `0x6057361d0000000000000000000000000000000000000000000000000000000000000005`
(first 4 bytes are function selector, rest is the encoded `5`).
---
Let’s split your msg.data:
`0x | 6057361d | 0000000000000000000000000000000000000000000000000000000000000005`
>`0x` → just means “this is hexadecimal”.
> `6057361d` → first 4 bytes (8 hex characters). This is the function selector.
> `0000....0005` → the next 32 bytes. This is the argument (5).
### **Call data**
* **Calldata** is the *input data* for a function call.
* It is **read-only**, stored in a special area of EVM memory.
* `msg.data` is literally the raw calldata.
So when you deploy or call a contract:
* The **constructor arguments** are encoded into the deployment transaction’s `data`.
* During a function call, the **selector + arguments** are encoded into calldata.
---
### `msg.data` in contract deployment
When you **deploy a contract**, the transaction has:
* `to = null` (because it’s deployment, not calling an existing contract).
* `data = <compiled bytecode + constructor arguments>`.
So here:
* `msg.data` = the **constructor arguments encoded**.
* That’s why during deployment, the constructor receives those values.
---
**Summary:**
* `msg.data` → Raw input data (function selector + encoded args).
* `msg.value` → Amount of ETH sent (in wei).
* `calldata` → Memory area where `msg.data` is stored, read-only.
* On deployment, `msg.data` = constructor’s arguments.
---