0

This question already has an answer here:

In Bitcoin blockchain, a set of transactions got stored in the block.In the ethereum blockchain, what is stored in the block? Where is the smart contract stored?or Whether the ethereum block contains both set of transactions and smart contract? Need Clarifications...I am a beginner

marked as duplicate by Richard Horrocks, Ismael, Badr Bellaj Apr 20 '18 at 21:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

I put together this presentation some time ago. Maybe this help explain some of it.

0

Blocks: They may be thought of as a bundle of transactions. But they are more than that.

Transaction: Transfer of ether or data between accounts.

Accounts: If they have data/code stored in their location, they are contract, else they are Externally Owned Account(EOA).

How does data go there?: When an EOA sends data and to field is empty in the transaction, that data is stored at a new address, and that new address is called contract address.

How contracts are executed?: Any further transaction sent to that new address will execute the code present at that address.

Where is the smart contract stored?

At an address.

How does it get executed?

Transaction

Let's look at a transaction. We are concerned with these aspects of a transaction:

  • from: Account address which sends the transaction
  • to: The address to which transaction is sent
  • data: The data which is sent in the transaction.
  • Value: The ethers which are sent to the to address.

The to address is contract address

It can be a contract address or an EOA. Contract can act differently on different data. Data generally consists of function hash and values of parameters given to that function. Contracts can also accept ether(specified in value field).

Now if contract is able to act on that particular data(if function which is called, is present), it displays its specified behavior. And we may say that contract has been executed.

If contract does not know what to do with the data which is given. The call will simply return immediately. There will be no code executed, but any value sent with the transaction will remain with the recipient contract.

To address is an EOA

On the other hand, if this data is sent to an EOA(EOA has no code at its address), no code would be run. So data would just stay there in the transaction.

  • please check my understanding.The smart contracts are compiled into bytecode and are stored in the blockchain? They get executed when necessary conditions are met and performs a transaction? – Jennings Apr 21 '18 at 3:46
  • Correct. That all bytecode is stored at an address. When any transaction is sent to that address, the code at that address gets executed. – Ayushya Apr 21 '18 at 3:52
  • Sorry again..What do you mean by "When any transaction is sent to that address, the code at that address gets executed ?".How a transaction triggers a smart contract? – Jennings Apr 21 '18 at 4:04
  • @johnny I have updated answer with more details. Let me know if there is anything which is unclear – Ayushya Apr 21 '18 at 5:54
  • the smart contracts are triggered by the transaction and this transaction contains enough ethers to execute smart contracts am I right? – Jennings Apr 21 '18 at 5:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.