0
votes

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)?

1
It's unclear what you're asking. Are you asking about the internals of how the blockchain data is stored in one of the Ethereum clients (e.g. geth or Parity)? If so, which one? If not, what are you asking about?user94559
@smarx Sorry for the confusion. I was asking how the data can be stored in the Ethereum chain as the format of bytecode.Jeff Hu
I still don't think I understand your question. A contract's code is stored as bytecode. Transactions aren't, and neither is a contract's state. Both of those are in Merkle trees, and the block headers contain the root hashes of those trees. Does that help?user94559
@smarx Yes thanks!! That is what I was asking! So when a new transaction reached the smart contract to change its state, all the previous transaction relevant to this smart contract will be iterated through to make sure the state change is good to have?Jeff Hu
That's theoretically correct, in that the current state is derived from all the previous transactions. But nodes persist that state as they go, so they don't need to process old transactions to reconstruct it again.user94559

1 Answers

-1
votes

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.