Ethereum Ethereum Basics

Table of contents

1. Ethereum definition

2. smart contract

3. Ethereum Accounts

4. EVM

5. Ethereum Client

6.Ethereum wallet

7. Gas

8. Ethereum Transaction

9. Ether

10. Ethereum Network

11. Ethereum key


1. Ethereum definition

Ethereum is a decentralized application platform built on blockchain technology . It allows anyone to build and use decentralized applications (DApps) that run on blockchain technology on the platform.

DApp is different from the application of the current Internet C/S architecture. Its backend is a network composed of N node computers (miners).

On the front end, users process their own data through their own wallets, and on the back end, the core logic uses smart contracts to run on the blockchain to achieve decentralization.

The node that the Dapp connects to the client is just a part of the network. It does not process the user's request alone (this request is usually called a "transaction"), but broadcasts the user's request to the entire network and waits for the entire network After a consensus is reached, the entire request is considered to be processed

2. smart contract

A smart contract is a program that runs on Ethereum, and like any other program, it consists of code and data. The data in the smart contract is also called "state", because the entire blockchain is a state machine determined by all data

Ethereum smart contracts are "Turing complete", so in theory we can use them to write programs that do anything. The following is a simple counter contract

pragma solidity ^0.8.0;
contract Counter {
    uint counter;
    constructor() {
        counter = 0;
    }
    function count() public {
        counter = counter + 1;
    }
}

3. Ethereum Accounts

The account model based on Transantion is used in Bitcoin, and the UTXO structure is used to store data about the user's balance. In this mode, the balance of each account is not explicitly recorded, and the UTXO with the user's private key needs to be calculated by itself. total value. (Strong privacy, but poor practicality)

The account-based model in Ethereum, each account includes a balance and data (code and internal storage) specially defined by Ethereum, there are two types of accounts in Ethereum:

1) External user account EOA

This type of account is controlled by a public key-private key pair (controlled by people), and can be used to send transactions (transfer coins or trigger contract call codes), which mainly contain the corresponding Ethereum balance, but there is no associated code

2) Contract account

This type of account is controlled by the code stored in the account, has the corresponding Ethereum balance and associated code and its own storage space, can trigger code execution through transactions or call messages from other contracts, and can operate its own storage space

·Account Status

Account status has 4 basic components

External user accounts and contract accounts are represented by the same address form, which is the same at the EVM level, and the address form is a 20-byte hexadecimal number.

The address of the external user account is deduced from the private key, and the address of the contract account is calculated from the creator's address and nonce

·nonce

If the account is an external user account, the nonce represents the transaction sequence number sent from this account address. If the account is a contract account, nonce represents the serial number of the contract created by this account

[Note]: There are two kinds of nonce in Ethereum, one is the account nonce—indicates the number of transactions of an account; the other is the proof of work nonce—a random number used to calculate the proof of work.

4. EVM

·def

The Ethereum Virtual Machine (Ethereum Virtual Machine) is the operating environment for smart contracts and is used to execute transactions on Ethereum. EVM can be understood as JVM. EVM is also a container for running programs. Contracts are usually written in solidity language, compiled into bytecode by EVM compiler, and finally deployed to the blockchain network through the client.

The Ethereum virtual machine is a completely isolated operating environment encapsulated by a sandbox. The code running in the EVM cannot access the network, file system and other processes, but can only access internal information

· EVM compatible chain

The prosperous Ethereum ecology has led to major public chains realizing that instead of developing their own unique virtual machines, it is better to take the initiative to be compatible with the Ethereum virtual machine, so that they can quickly undertake Ethereum applications

Currently popular EVM-compatible chains include: Polygon chain, BNB chain (BSC), OK chain, Avalanche C chain, Fantom, etc. They use the same address format as the Ethereum chain, use the same EVM code, and support Ethereum development tools and wallets.

Custom RPCEach chain has its own chainId and corresponding node RPC, which we can add in MetaMask by adding a custom network RPC ( )

5. Ethereum Client

The Ethereum client is a software application program, which is a node program in the Ethereum network. After running the node program, it can join the blockchain network and become a node. This node program can complete tasks such as creating accounts, initiating transactions, deploying contracts, executing contracts, and mining blocks.

Common Ethereum clients include:

6.Ethereum wallet

The Ethereum wallet is the gateway to the Ethereum system. It contains the private key and can create and broadcast transactions on our behalf. The common wallets are:

1) metamask is a browser extension wallet that can run on the browser and can be used in conjunction with Remix to deploy and execute smart contracts

2) jaxx is a multi-platform and multi-currency wallet that can run on various operating systems

3) myetherwallet is a web-based wallet that can run in any browser

7. Gas

As mentioned earlier, smart contracts running on the EVM are "Turing-complete", and theoretically it is possible to write programs that can do anything. That being the case, a malicious executor can easily bring down the network by executing a transaction that contains an infinite loop.

Ethereum protects the network from deliberate attacks by charging a certain fee for each transaction. This charging mechanism is called the Gas mechanism

Gas is a measure of how much "work" an operation or set of operations needs to perform. For example, computing a Keccak256 cryptographic hash function requires 30 Gas per hash calculation, plus 6 Gas per 256 bits of data being hashed. Every operation performed on the EVM consumes a certain amount of Gas, and operations that require more computing resources also consume more Gas.

Understanding: Gas can be regarded as the operating fuel of the Ethereum virtual machine. It consumes a certain amount of Gas every time it executes a step. If the given Gas is not enough, no matter where it is executed, it will trigger an out-of- gas exception, all state modifications made by the current transaction will be reverted.

8. Ethereum Transaction

The function call information is encapsulated in the DATA field, and the transaction information is sent to the address of the smart contract to be called

· Specific data structure

Transactions are serialized binary messages containing the following data:

9. Ether

ETH, for users, the most commonly used is ether, 1 ether is what we often call an ether (usually referred to as ether), and for developers, the most commonly used is wei, which is the smallest value of ether. Units, other units include finney, szabo, among which wei has several derived units: Kwei, Mwei and Gwei

1 ether == 10^3 finney(即1000 finney)

1 ether == 10^6 szabo

1 ether == 10^18 wei

1 Gwei == 10^9 wei

1 Mwei == 10^6 wei

10. Ethereum Network

There are different networks in Ethereum. What we usually call Ethereum is its main network, which is the real Ethereum blockchain, and the main network is the real value network.

And we can also use the test network for testing and other work . The test network will provide faucets for developers to receive free test coins. For example, Ethereum provides Goerliand Sepoliatestnet, Polygonwhich provides Mumbaitestnet

11. Ethereum key

1) private key Ethereum private key is a 256-bit random number used to create a signature in the transaction of sending ether to prove the ownership of funds

2) public key The public key of Ethereum is a 512-digit number generated one-way by the private key through the elliptic encryption curve secp256k1 algorithm

3) address The address is an identifier derived from the last 20 bytes of the keccak256 one-way hash of the public key


[Note]: Some content is incomplete due to audit reasons

Guess you like

Origin blog.csdn.net/weixin_46516647/article/details/131463664