Ethereum: Smart Contracts and Nodes

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Which of the following programming languages is Turing-complete and designed for writing smart contracts on Ethereum?

  • Go
  • Solidity (correct)
  • Bitcoin Script
  • JavaScript

What is the primary role of miners in the Ethereum network?

  • Validating transactions and producing blocks (correct)
  • Executing smart contracts
  • Maintaining account balances
  • Storing the entire blockchain ledger

Approximately how long does it take to generate each block in the Ethereum blockchain?

  • 1 minute
  • 10 minutes
  • 1 hour
  • 15 seconds (correct)

What metadata is contained within a block header in the Ethereum blockchain?

<p>Metadata about the block and the previous block (D)</p> Signup and view all the answers

What is the 'nonce' in the context of a block header?

<p>The number found by a miner to solve a cryptographic puzzle (D)</p> Signup and view all the answers

What role does the Ethereum Virtual Machine (EVM) serve in the Ethereum ecosystem?

<p>Executing smart contracts (C)</p> Signup and view all the answers

What is the purpose of EVM bytecodes?

<p>To represent smart contracts in a format that the EVM can execute (D)</p> Signup and view all the answers

What is the maximum number of decimal places to which 1 ETH can be subdivided?

<p>18 (A)</p> Signup and view all the answers

What term is used to describe the 'fuel' required to perform any transaction on the Ethereum network?

<p>Gas (B)</p> Signup and view all the answers

To whom do transaction fees go?

<p>Miners (B)</p> Signup and view all the answers

What happens if a transaction requires more gas than the specified limit?

<p>The transaction fails, and gas is consumed as part of the transaction fees. (A)</p> Signup and view all the answers

If a transaction uses less gas than the specified limit, what happens to the excess gas?

<p>It is refunded back to the wallet. (D)</p> Signup and view all the answers

In what unit is the gas price always defined?

<p>Gwei (D)</p> Signup and view all the answers

How do miners decide whether to process a transaction?

<p>Based on the gas price offered (C)</p> Signup and view all the answers

What is the fixed gas limit required for a simple ether transfer transaction?

<p>21,000 (A)</p> Signup and view all the answers

What term is used to describe the accounts a wallet can hold?

<p>Externally Owned Accounts (EOA) (C)</p> Signup and view all the answers

Which of the following is true of both Externally Owned Accounts and Contract Accounts?

<p>Both EOAs and Contract Accounts can hold balances of ETH. (C)</p> Signup and view all the answers

How long is an Ethereum account address, in bytes?

<p>20 bytes (A)</p> Signup and view all the answers

What does 'off-chain' mean in the context of wallet creation?

<p>The wallet is created outside of the blockchain. (C)</p> Signup and view all the answers

Which type of account needs an EOA account to be created or used?

<p>Contract Account (CA) (B)</p> Signup and view all the answers

What is the purpose of Abstract Binary Interfaces (ABIs) in the context of Ethereum smart contracts?

<p>To enable EOAs to access functions of a smart contract (A)</p> Signup and view all the answers

Which of the following initiates the transaction first, so that contracts can initiate other transactions?

<p>Externally Owned Account (EOA) (C)</p> Signup and view all the answers

What is the term used to describe transactions initiated by contracts?

<p>Internal transactions (D)</p> Signup and view all the answers

What happens when transferring ETH from one EOA to another EOA?

<p>The data field is empty (B)</p> Signup and view all the answers

What is specified by the 'Nonce' transaction field?

<p>Specifies the execution order of the transactions initiated from an EOA. (D)</p> Signup and view all the answers

What is the role of the transaction hash?

<p>Track the status of the transaction and cancel or drop the transaction before it gets executed (D)</p> Signup and view all the answers

What happens when a transaction initiator sets the gas price too low?

<p>The transaction waits to be executed by the nodes and can remain in a pending state. (B)</p> Signup and view all the answers

What is a 'successful transaction'?

<p>A transaction that is executed successfully without any failure. (A)</p> Signup and view all the answers

Which of the following are true about 'mainnet'?

<p>Testnets are the replica of the mainnet and behave the same (A)</p> Signup and view all the answers

What is required to deploy and test contracts on Testnets?

<p>Testnet Ethers (B)</p> Signup and view all the answers

What characteristic defines smart contract code after its deployment on the blockchain?

<p>Immutable (D)</p> Signup and view all the answers

What type of transactions does storage space have limitations?

<p>Smart contract transactions (C)</p> Signup and view all the answers

What should the transaction initiator pay, to execute a smart contract's logic?

<p>Gas in ether (C)</p> Signup and view all the answers

What is a result of DAO Smart Contract hack?

<p>The creation of the Ethereum (ETH) and Ethereum Classic (ETC) (D)</p> Signup and view all the answers

What is the current Ethereum's consensus algorithm as of July 2024?

<p>Proof of Stake (PoS) (D)</p> Signup and view all the answers

To become a validator, what does the Stake ETH do?

<p>Lock up 32 ETH to become a validator. (C)</p> Signup and view all the answers

What is the approximate Ethereum's block time?

<p>~12 seconds (B)</p> Signup and view all the answers

Approximately how long does it take to finalize blocks?

<p>12.8 minutes (B)</p> Signup and view all the answers

What is the purpose of the miners/validators' ability to vote to increase or decrease the gas limit?

<p>Balances network throughput, resource usage, and decentralization (A)</p> Signup and view all the answers

How much gas is required for a simple ETH transfer?

<p>21,000 gas (B)</p> Signup and view all the answers

What are Gas Costs for Opcodes?

<p>Predefined costs for EVM operations (D)</p> Signup and view all the answers

Flashcards

What is Ethereum?

Ethereum is an open source, public, and decentralized computing platform that is an implementation of blockchain technology.

Bitcoin Scripts Functionality

Scripts in Bitcoin have limited functionalities, making complex scripts difficult to write.

Solidity's Capability

Ethereum's scripting language, Solidity, is Turing-complete and allows for the creation of complex smart contracts.

Full Node in Blockchain

A full node maintains the complete blockchain ledger and verifies every block and transaction using consensus rules.

Signup and view all the flashcards

What are Miners?

Nodes that perform transaction execution and verification. They contribute computing resources and collect block rewards and transaction fees.

Signup and view all the flashcards

What is the genesis block?

The first block in the blockchain. It is very important.

Signup and view all the flashcards

What is Block Header?

Stores metadata about the block and the previous block, linking blocks together in the blockchain.

Signup and view all the flashcards

What is Parent Hash?

Points to the parent block of the newly generated block.

Signup and view all the flashcards

What is Nonce?

A number found by the miner to solve a cryptographic puzzle, securing the block.

Signup and view all the flashcards

What is Timestamp?

The time when a block is found and added to the blockchain.

Signup and view all the flashcards

What is Transactions Root?

The Keccak 256-bit hash of the root node of the tree structure, which is populated with each transaction.

Signup and view all the flashcards

What is EVM?

Runtime environment for smart contracts in Ethereum.

Signup and view all the flashcards

What is Wei?

The smallest value of 1 ETH and is used for paying transaction fees.

Signup and view all the flashcards

What is gas in Ethereum?

Gas is the fuel of the Ethereum blockchain network and is paid in ether.

Signup and view all the flashcards

What are bytecodes?

Fixed quantities that make up a transaction in EVM.

Signup and view all the flashcards

What is gas price?

You specify how much to pay for a transaction.

Signup and view all the flashcards

What is gas limit?

You tell the network the max limit to use for a transaction.

Signup and view all the flashcards

What is extra gas?

Returned to the wallet if a transaction uses less gas than the gas limit.

Signup and view all the flashcards

What is the gas price?

The price per gas unit that one is willing to pay for executing a transaction.

Signup and view all the flashcards

Fixed gas limit

The amount of gas set to a fixed amount for transfer.

Signup and view all the flashcards

What are EOAs?

Accounts that are controlled by private keys, used to initiate transactions.

Signup and view all the flashcards

What are Contract Accounts (CA)?

Accounts that have code and code logic that controls the flow of funds and states of the contract.

Signup and view all the flashcards

What do the accounts hold?

Holds balances of ETH, and their addresses are written in hexadecimal format, starting with "0x."

Signup and view all the flashcards

How are keys made?

Ethereum wallet creation service generates new private keys, from which the public key is derived.

Signup and view all the flashcards

What is a transaction's main purpose?

An Ethereum blockchain transaction requires transferring ETH or interacting with smart contracts.

Signup and view all the flashcards

What are internal transactions?

Transaction initiated by contracts.

Signup and view all the flashcards

What does Nonce specify?

Specifies the transaction processing order.

Signup and view all the flashcards

What is Transaction Hash?

Allows you to track the status of the transaction and cancel or drop the transaction before it gets executed.

Signup and view all the flashcards

What is Pending Status?

Status where the transaction is waiting to be executed by nodes.

Signup and view all the flashcards

What is a Successful Transaction?

Successful transaction without any failure.

Signup and view all the flashcards

What is Fail status?

A transaction is executed and, may fail due to an error during contract method execution.

Signup and view all the flashcards

What is Dropped Status?

The transaction is dropped from the Ethereum network.

Signup and view all the flashcards

Change Transaction Fields

Some transaction fields can be changed, to increase value or keep the nonce.

Signup and view all the flashcards

Cancel Transactions

Use a new transaction with the same nonce and own info to give greater priority.

Signup and view all the flashcards

What are testnets?

Useful for contract code testing. They mimic blockchain.

Signup and view all the flashcards

What is mainnet?

The replica of the mainnet where you can test your contracts.

Signup and view all the flashcards

What are faucets?

Tools that lets you get testnet others.

Signup and view all the flashcards

What is etherscan.io?

Blockchain ledger explorer.

Signup and view all the flashcards

What do Smart Contracts allow users?

Enabling direct P2P transactions and automating obligations.

Signup and view all the flashcards

What is Contract Code? (Immutable)

Is immutable once deployed, only states/variables can be changed.

Signup and view all the flashcards

Study Notes

Introduction to Ethereum

  • Proposed in 2013 by Vitalik Buterin.
  • First production release was in 2015.
  • Ethereum is an open source, public, decentralized computing platform.
  • It's popular due to the features of its smart contracts.

Smart Contracts and Solidity

  • Bitcoin scripts are not Turing-complete, and Bitcoin scripts have limited functionalities making complex scripts difficult to write
  • Ethereum makes writing complex smart contracts easy.
  • Solidity: Turing-complete language used for writing smart contracts.

Nodes

  • Full nodes maintain the complete blockchain ledger data structure.
  • Full nodes verify every block and transaction using defined consensus rules.
  • Lightweight nodes verify transactions using Simple Payment Verification (SPV).
  • SPV doesn't require downloading the entire blockchain because it only downloads header info.
  • Miners execute and verify transactions.
  • Miners contribute computing/storage resources and receive block rewards and transaction fees.

Blocks

  • The blockchain maintains a series of blocks, linked together.
  • The first block is called the "genesis block."
  • Blocks contain multiple transactions
  • Blocks are generated using a consensus algorithm.
  • Each block is generated in approximately 15 seconds.
  • Miners who generate blocks are rewarded.
  • Each block has a defined gas limit.
  • Transactions in a block cannot exceed the block's gas limit. The blockheader contains metadata about the block and the previous block.

Block Header Fields

  • Parent Hash: Points to the previous block.
  • Nonce: Number found that solves the cryptographic puzzle
  • Timestamp: The time the block was added to the blockchain.
  • Transactions Root: Keccak 256-bit hash of the root node of the tree structure (populated with each transaction).

Ethereum Virtual Machine (EVM)

  • EVM: Runtime environment for smart contracts.
  • Ethereum supports multiple scripting languages.
  • Smart contracts compile/convert to EVM bytecodes.
  • Bytecodes are executed by EVM to perform smart contract operations.

Ether (ETH)

  • Ether is a fungible coin, and is divisible into smaller units.
  • 1 ETH has a maximum of 18 decimal places and the smallest value is called wei.
  • Ether fuel for the Ethereum network.
  • Gas is paid in ether, which is consumed when a transaction is executed
  • Transaction fees go to the miners.
  • Solidity supports wei, finney, szabo, and ether units.

Gas

  • Gas is the fuel used on the Ethereum blockchain and it is paid in ether.
  • Gas price and limit must be specified for each transaction.
  • The network calculates the transaction fee based on gas price and limit.
  • Each EVM bytecode operation has fixed gas units.
  • Executing operations consumes a fixed quantity of gas.
  • If a transaction uses less gas than the limit, excess gas is refunded.
  • Transactions consuming all gas that need more, will fail and gas will be consumed as part of the transaction fees.
  • Gas price is the cost per gas unit is defined in gwei.
  • Miners process transactions based on gas price.
  • An ETH transfer requires 21,000 gas limit per transaction.

Accounts

  • Two account types exist: Externally Owned Accounts (EOA) and Contract Accounts (CA).
  • Both EOAs and CAs can hold ETH balances.
  • Account addresses are written in hexadecimal (starting with "0x") and are 20 bytes (160 bits) long.
  • Ethereum wallets can hold multiple EOAs.
  • New private keys are generated using specific algorithms by wallet creation services.
  • Public keys are derived from private keys.
  • The combination of public and private keys is an EOA.
  • EOAs are controlled by private keys, which are used to start transactions.
  • Wallets are created via off-chain wallet generation algorithms.
  • Contracts only have public addresses, and their code logic controls funds' flow
  • An EOA account is necessary to create/interact with a contract.
  • Contract accounts have Solidity code that defines behavior.
  • Contract accounts can only be created on-chain.
  • Contract bytecode is included in block during successful deployment.

Transaction

  • Transactions transfer ETH from EOA for smart contracts.
  • They can change state, perform actions, or read contract states.
  • Transactions can only be initiated from an EOA and then initiate other internal transactions.
  • Users first complete required fields to create a tx.
  • Then they sign the transaction with the EOA's private key.

Transaction Fields

  • From: Public address of EOA initiating the transaction.
  • Transactions initiated by contracts are internal transactions.
  • To: Public address of an EOA or contract.
  • Value: Transactions can have zero or nonzero value.
  • Set to nonzero when sending ETH to an EOA.
  • When initiating a transaction to a contract, the value field either has a zero or nonzero based on the contract function.
  • Gas limit and gas price must be specified
  • Nonce: Starts at zero for an EOA and increases by one for each transaction, specifying execution order.
  • Data: It will be empty when transferring ETH one EOA to another EOA.
  • To execute another method the data field will hold hexadecimal value of the method and its arguments.
  • Transaction Hash is the SHA-256 hash of the signed transaction data.
  • The transaction can be tracked with this ID and dropped before it gets executed.

Transaction Status

  • A transaction can have below statuses:
  • Pending: Waiting to be executed; may take longer if gas price is too low.
  • Transaction initiators are allowed to change transaction fields by sending a new transaction with the same nonce.
  • Successful: Executed successfully w/o failure.
  • Fail: Executed with a contract method execution error or due to low gas limit.
  • Dropped: Transactions get dropped for different reasons that includes pending status and low gas price.
  • Gas and ETH are returned to wallets with a dropped transaction.

Pending Transaction Operations

  • To change initiated transaction fees/ fields, the value can be changed and keeping the same gas price.
  • A transaction can be canceled by initiating self transaction.
  • New transactions must have higher gas to be given priority over older one.

Testnets

  • Testnets replicate the mainnet (production) Ethereum blockchain.
  • Ether is required to deploy and test contracts on testnets.
  • Testnet ethers can be acquired from a faucet for free.
  • Contracts can locally tested by Private Testnet setup or Ganache.

Smart Contracts

  • Nick Szabo coined the term "smart contract" in 1994.
  • Smart contracts eliminate intermediaries, allowing direct P2P transactions.
  • They automatically enforce some obligations.
  • Smart contract code is immutable once deployed.
  • A different mindset is required for smart contract creation.

Immutable Code

  • Smart contract code cannot be changed. However, states and variables can be.
  • Smart contract code behavior changes based on states and variables.
  • There is no way to the reverse a state change of a smart contract.

Storage and Gas

  • Smart contract storage is costly.
  • The ethereum blockchain cannot handle large amounts of data.
  • Execution of transactions is limited by gas limit per block.
  • Every transaction that sends ether consumes gas.
  • Transaction initiators must pay gas in ether for executing smart contract logic

Hacks

  • DAO Smart Contract hack that occurred in June 2016, which lead to 3.6 million ETH theft worth $50 million.
  • The hack lead to Ethereum (ETH) and Ethereum Classic (ETC).
  • Parity Multisignature Wallet Hack that happened in 2017 resulted in millions of dollars lost, due to vulnerability in the Parity wallet.

Consensus

  • Ethereum's consensus algorithm is Proof of Stake (PoS), specifically Gasper - effective as of July 2024.
  • To become a validator lock up 32 ETH.
  • Operate a Beacon Chain and Execution Layer client.

Block Time and Block Reward

  • Ethereum's block time (PoS) is about 12 seconds.
  • Blocks must be finalized after 12.8 minutes.
  • Block reward in PoS is dynamic and is based on the amount of ETH staked and validator participation.
  • The base reward is estimated as ~0.025 ETH per block (dependent upon total ETH staked).

Gas Limit

  • This is a consensus parameter defined to limit the amount of computation that can be included in a block, it's known as Gas Limit per Block.
  • The gas limit is defined in a range of 30 millio gas (as of 2024).
  • The gas limit per block is defined to balance network throughput, resource usage, and decentralization.
  • This can be manually adjusted by Miners/validators that can vote increase or decrease it.

Transaction Fee

  • Gas for ETH Transfer: is estimated 21,000 gas.
  • Extra gas for data or smart contract interactions is defined as Additional Costs.
  • Gas Costs for Opcodes such as EVM operations are also components that increase the amount of gas required
  • In order to ensure fair pricing, prevent abuse, as well as maintain network stability gas is measured as a fee.
  • Opcodes in general have variable costs based on input size or context which also affect gas consumption.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Solidity
8 questions

Solidity

ProblemFreeHeliotrope5400 avatar
ProblemFreeHeliotrope5400
Solidity
5 questions

Solidity

DiligentJade avatar
DiligentJade
Solidity Chapter 2: Contracts
5 questions
Use Quizgecko on...
Browser
Browser