Govur University Logo
--> --> --> -->
...

When a smart contract gets information from outside, where does the EVM first put this information so the contract can only read it?



When a smart contract needs information from outside the blockchain, such as a price feed from an oracle, this information must be included as part of a transaction that calls the smart contract. The EVM does not directly fetch external data; instead, an external entity, like an oracle service, initiates a transaction to the contract, embedding the external data within that transaction. This external information is primarily placed within the `data` field of that transaction, which the EVM makes available to the contract as `calldata` during execution. `Calldata` is a special, read-only, byte-addressable segment of memory that holds the input arguments for a contract function call, along with the function selector. When the EVM begins executing the contract code, it makes this `calldata` accessible. The smart contract accesses this information using specific EVM opcodes like `CALLDATALOAD` to read 32-byte words, `CALLDATASIZE` to determine its total length, or `CALLDATACOPY` to copy portions of it into transient memory. `Calldata` is transient; it exists only for the duration of the transaction execution and is not stored permanently on the blockchain as part of the contract's state. From the contract's perspective, it can only read this `calldata`; it cannot modify its contents. If the contract needs to store this information persistently, it must explicitly write it to its own `storage`.