Ethereum

Ethereum transaction

While a transaction is being executed, the EVM consumes its gas. Two outcomes are possible at the end of the transaction:

  1. The transaction completes successfully. In this case, the unused gas is returned to the sender.
  2. The amount of gas available ends before the completion of the transaction. In this case, the EVM throws an end of gas exception, and the transaction is rolled back.

For the second outcome, even though the EVM throws an exception, the miner still charges the gas in Ether

Calls and transactions

Calls

A call is sent through a message that doesn't get stored on the blockchain and whose execution has the following characteristics

  • It can only perform read-only operations, which don’t alter the state of the blockchain.
  • It doesn’t consume any gas, and consequently, it’s free.
  • It’s processed synchronously.
  • It immediately returns a return value.
  • It doesn’t allow transferring Ether to the contract account

Transactions

A transaction is sent through a message that gets serialized and stored on the blockchain during mining process. It contains the following fields:

  • Sender address
  • Recipient address
  • Value—Amount of Ether to be transferred (in Wei), in case the message is being used to transfer Ether (optional)
  • Data—Input parameters, in case the message is being used as a function call (optional)
  • StartGas—Maximum amount of gas to be used for the execution of the message. If this limit is exceeded, the EVM throws an exception and rolls back the state of the message.
  • Digital signature—Proves the identity of the transaction sender
  • GasPrice—The price of a unit of gas (expressed in Ether) the transaction initiator is willing to pay.

The execution of a transaction has the following characteristics

  • It can perform write operations, which alter the state of the blockchain.
  • It consumes gas, which must be paid for in Ether.
  • It’s processed asynchronously: it gets executed through mining and then gets appended on a new blockchain block, which gets broadcast throughout the network.
  • It immediately returns a transaction ID, but not a return value
  • It allows transferring Ether to the contract account.

Nodes

The network contains two broad categories of nodes:

  • Miners: They process the latest transactions and consolidate them into the blockchain in exchange for transaction fees and a mining reward
  • Full nodes: They mainly verify the validity of the blocks they’ve received from neighboring peers and keep propagating them to the rest of the network. Therefore, they’re considered consumers.

Timestamp

When a miner broadcasts a newly mined block, its timestamp is validated by checking whether the timestamp is greater than the current timestamp. If a miner uses a timestamp greater than the previous block timestamp and less than the current timestamp, the difficulty would be higher, and therefore, it would take more time to mine the block.

Due to these reasons, miners always use accurate timestamps, otherwise they gain nothing.

Transaction nonce

Every transaction has a nonce associated with it. A nonce is a counter that indicates the number of transactions sent by the sender of the transaction. If we are using a nonce greater than the nonce the transaction should have, then the transaction is put in a queue until the other transactions arrive. For example, if the next transaction nonce should be 4 and if we set the nonce to 10, then geth will wait for the middle six transactions before broadcasting this transaction. This is called a queued transaction.

Hierarchical deterministic wallet

A hierarchical deterministic wallet is a system of deriving addresses and keys from a single starting point called a seed. This makes it easier to back up and store multiple accounts, as you just have to store the seed, not the individual keys and addresses.

Why will users need multiple accounts?

The reason is to hide their wealth.

Key derivation functions

A key derivation function (KDF) is a deterministic algorithm to derive a symmetric key from some secret value (such as master key, password, or passphrase). There are various types of KDFs, such as bcrypt, crypt, PBKDF2, scrypt, HKDF, and so on.

Last updated on