Search code examples
bytecodeblockchainethereumsmartcontracts

How is a smart contract lived on Ethereum (stored and opened for state change)


A smart contract can be compiled into EVM bytecode (Ethereum Virtual Machine) and deployed to Ethereum blockchain on a block with specific block height, and return a transaction hash.

But in what way does a smart contract stored on a block? And how does the blockchain record state change, when a transaction has been issued to interact with that smart contract to change its state (e.g. the value of a variable)?


Solution

  • You need to distinguish two things stored in blokchain (both of them are stateless and immutable):

    • smart contract templates
    • transactions/events

    Final smart contract state isn't stored in blocks directly. It is computed by node (ethereum virtual machine) from previously mentioned templates and transactions.