banner
[面包]MrTwoC

[面包]MrTwoC

你好,欢迎来到这个基于区块链的个人博客 名字:面包 / MrTwoc 爱好:跑步(5/10KM)、咖啡、游戏(MMORPG、FPS、Minecraft、Warframe) 兴趣方向:Rust、区块链、网络安全、量子信息(量子计算)、游戏设计与开发
bilibili
steam
email
github

Solidity.1. Ethereum Core Concepts

https://decert.me/tutorial/solidity/intro

Solidity is a programming language designed specifically for the Ethereum platform.

1 Account#

  1. External Owned Account (EOA)
  2. Contract Account

Features:
The address format is the same, a 20-byte hexadecimal number.
Transactions can only be initiated by external accounts, and all gas fees are paid by external accounts.

2 Account State#

Four basic components:
nonce:
Divided into two types: 1- the number of transactions of an account, 2- proof-of-work nonce (used to calculate a random number that satisfies the proof-of-work)
EOA: the sequence number of transactions sent from this account
Contract Account: the sequence number of contracts created by this account
balance:
The amount of Ether balance owned, unit: Wei, 1 ether = 10^18 wei. The balance will change when Ether is traded. Both EOA and contract accounts have balances; contract accounts use code to manage the funds they own, while external user accounts spend funds using private key signatures; contract accounts store code, while external user accounts do not.
storageRoot:
The hash value of the root node of the Merkle Patricia tree. The Merkle tree encodes the hash value of the stored content of this account by default, which is an empty value.
codehash:
The hash value of the account code.
Contract Account: the result of hashing the contract code
EOA: empty string hash value
A visual example to summarize the above content:
image

3 Ether#

The currency of Ethereum, similar to different denominations in fiat currency. The most commonly used by users is ether, while developers often use wei. Wei is the smallest unit of ether, and there are also two units called finney and szabo. Derived units of wei: Kwei, Mwei, Gwei

1 ether = 10^3 finney (i.e., 1000 finney)
1 ether = 10^6 szabo
1 ether = 10^18 wei
1 Gwei = 10^9 wei
1 Mwei = 10^6 wei

4 Ethereum Virtual Machine (EVM)#

A virtual computer used to execute smart contracts and Dapps. The EVM is one of the core components of Ethereum and is responsible for processing and executing smart contract code.
The working principle is similar to that of traditional virtual machines, but it is specifically designed for blockchain and smart contracts. It is an automated contract on Ethereum.
Executing smart contracts: load the bytecode of the smart contract into memory and execute it according to predetermined rules.
gas: Prevent malicious code from consuming resources in an infinite loop.

5 Ethereum Client#

A node program that connects to the Ethereum network. The EVM is an important component of the client. By running the node program, it can become one of the nodes in the Ethereum network.
Two levels
Execution layer:
Responsible for transaction execution, including smart contract deployment and execution
Consensus layer:
Responsible for handling consensus algorithms, i.e., block generation and transactions
Execution layer clients:
Geth (official-Go language implementation), Nethermind (C# implementation), and Erigon (Go language implementation). These clients are used to handle smart contract operations and transaction execution on the Ethereum network.
Consensus layer clients:
Prysm (Go language implementation) and Lighthouse (Rust implementation). These clients participate in the consensus process to ensure the consistency and security of the blockchain network.

6 Wallet#

An important tool for managing accounts, wallets can be used to create accounts, sign transactions, and connect to blockchain nodes to execute transactions. Wallets themselves do not store users' assets, but manage the keys and signature functions that access these assets.
Common mobile wallets: ImToken, Trust Wallet
Web wallets: MetaMask, Phantom (Solana)

7 Gas Mechanism#

Introduced to prevent malicious behavior, it is the unit that measures the workload required to perform an operation. Equivalent to a transaction fee.

8 Ethereum Transactions#

Three types

  1. Normal transaction
  2. Contract creation
  3. Calling a contract function
{
  "to": "0x687422eEA2cB73B5d3e242bA5456b782919AFc85",
  "value": 0.0005,
  "data": "0x" // Can include a message or comment
}
This is a very simple normal transaction that transfers a certain amount of Ether to the specified address,
and if desired, can include a message in the transaction.
{
  "to": "0x687422eEA2cB73B5d3e242bA5456b782919AFc85", // Contract address
  "value": 0.0,
  "data": "0x06661abd"
}
The information for calling a smart contract function is encapsulated in the DATA field and sent to the address of the smart contract to be called. Assuming we want to call the count() function mentioned earlier, the selector of the count() function is passed.
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.