Preface
Understanding the underlying mechanism of smart contracts is crucial for writing secure and efficient code.
From Source Code to Bytecode
- Source Code: It is human-readable code written in Solidity.
- Compiler: The source code is processed by a compiler, which optimizes it and converts it to low-level code understandable by machines.
- Bytecode: The compiler outputs bytecode, which is optimized code that is hard for humans to read.
Deployment
- When deploying a smart contract, bytecode, not source code, is sent to the blockchain.
- Once the transaction is mined and added to the blockchain, the contract is successfully deployed and its code is immutable.
Smart Contract Execution
- EVM (Ethereum Virtual Machine) is an environment that executes smart contract bytecode, essentially acting as a bytecode interpreter.
- Every full node in the Ethereum network runs an EVM instance to verify and execute transactions.
Interaction Methods
- Transaction:
- To modify the contract's state, a transaction must be sent.
- Transactions require a Gas fee and are asynchronous, so the completion time is uncertain.
- Transactions cannot directly return values; results must be obtained via events or subsequent calls.
- Call:
- Calls are used to read contract state without modifying it.
- Calls are free and instantaneous as they execute locally without requiring network-wide consensus and can return values directly.
Top comments (0)