0

Ethereum newbie here with some general programming knowledge including basic Solidity. Below is my current mental picture of how Ehtereum works (please correct me if wrong).

A contract is a class (in OOP term) contains a bunch of functions that can be called by anybody once deployed on the blockchain. Each function may or may not contain ether transactions.

So if I consider ether the same as bitcoin, then the Ethereum blockchain should contain a list of blocks, with each block containing a bunch of ether transactions including the reward for the miner of that block.

But sometimes I also got the impression that the Ethereum blockchain is actually a list of contracts, as each contract has an "address" and being immutable once deployed.

Which one is true (or neither)?

2

the Ethereum blockchain should contain a list of blocks, with each block containing a bunch of ether transactions including the reward for the miner of that block.

Each block is a well-ordered list of transactions that were accepted by the network. The blocks themselves are well-ordered, so the blockchain is a well-ordered set of transactions. Transactions are allowed or disallowed depending on whether they follow protocol (correct signature, has enough money, acceptable to the receiving contract, etc.)

I also got the impression that the Ethereum blockchain is actually a list of contracts, as each contract has an "address" and being immutable once deployed.

In addition to the from and to accounts and amount, ethereum protocol includes the amount of gas and the gasPrice (a sort of priority) and, importantly data.

A specially crafted transaction sent to address(0) can contain compiled bytecode for a smart contract in the data field. If this transaction is acceptable, then the contract is assigned an address. Such contract addresses are virtually indistinguishable from wallet addresses. These deployment transactions make the "fact" of the deployed contract apparent to all observers.

Contracts have named functions (e.g. deposit, withdraw, transfer) and addresses in the same format as externally owned accounts (wallets). So, one can sign a transaction and address it to a contract instead of to another wallet. The data field will usually contain additional information such as the function to invoke and arguments to pass in. Contracts have no choice except to process the incoming transactions and messages from other contracts.

A contract is a class (in OOP term) contains a bunch of functions that can be called by anybody once deployed on the blockchain. Each function may or may not contain ether transactions.

Contracts are virtually indistinguishable from wallets but they have code instead of private key holders. They have internal storage space so they are stateful. They have functions that can update the state or report it.

There are patterns that closely resemble OOP but that is largely a matter of style. Deep down they are more like stateful application network protocols. Once deployed they can't be amended and their internal state (which is the obvious result of the code and all the transactions that have been sent to the contract) is immutable.

You will find considerable discussion about upgradeable contract patterns that, I think, obfuscate the facts for newcomers. A contract cannot be changed once released, but the initial release may include intentionally modular and upgradeable design. For example, delegating a process to another contract and some kind of procedure to reassign responsibility from time to time.

The machine-level code is defined at the protocol layer. Developers generally use a higher-level language such as Solidity to write the contracts in human-readable form and then compile the source code into bytecode for the Ethereum Virtual Machine.

Hope it helps.

  • Thanks! It is a lot to digest. Is it correct to say: a contract is a transaction, a contract is also an account (wallet)? If yes, then is an account also a transaction, or the other way around, or should I abandon this is-a type of thinking on relationships between objects in the Ethereum universe? – Indominus Jul 9 '18 at 0:53
  • A contract is machine code with an address that gets deployed via a special transaction. Instead of "Alice sends Bob 5 BTC", "Alice deploys the code with instructions 0x660.... resulting in the contract at address 0x123..." Bob sends a transaction to 0x123... causing something to happen. – Rob Hitchens - B9lab Jul 9 '18 at 1:04
  • So, "Bob sends a transaction to 0x123..." is basically Bob calling some functions on the deployed contract? – Indominus Jul 9 '18 at 2:00
  • Close enough for conversation. ;-) – Rob Hitchens - B9lab Jul 10 '18 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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