Помогите перевести эту страницу


Вы просматриваете эту страницу на английском языке, потому что мы еще не перевели ее. Помогите нам перевести эти материалы.

Эта страница не завершена. Если вы эксперт по теме, пожалуйста, отредактируйте эту страницу и добавьте в нее известную вам информацию.


Последнее редактирование: , Invalid DateTime
Редактировать страницу

Transactions are cryptographically signed instructions from accounts. An account will initiate a transaction to update the state of the Ethereum network. The simplest transaction is transferring ETH from one account to another.


To help you better understand this page, we recommend you first read Accounts and our introduction to Ethereum.

What's a transaction?

An Ethereum transaction refers to an action initiated by an externally-owned account, in other words an account managed by a human, not a contract. For example, if Bob sends Alice 1 ETH, Bob's account must be debited and Alice's must be credited. This state-changing action takes place within a transaction.

Diagram showing a transaction cause state change Diagram adapted from Ethereum EVM illustrated

Transactions, which change the state of the EVM, need to be broadcast to the whole network. Any node can broadcast a request for a transaction to be executed on the EVM; after this happens, a miner will execute the transaction and propagate the resulting state change to the rest of the network.

Transactions require a fee and must be mined to become valid. To make this overview simpler we'll cover gas fees and mining elsewhere.

A submitted transaction includes the following information:

  • recipient – the receiving address (if an externally-owned account, the transaction will transfer value. If a contract account, the transaction will execute the contract code)
  • signature – the identifier of the sender. This is generated when the sender's private key signs the transaction and confirms the sender has authorized this transaction
  • value – amount of ETH to transfer from sender to recipient (in WEI, a denomination of ETH)
  • data – optional field to include arbitrary data
  • gasLimit – the maximum amount of gas units that can be consumed by the transaction. Units of gas represent computational steps
  • maxPriorityFeePerGas - the maximum amount of gas to be included as a tip to the miner
  • maxFeePerGas - the maximum amount of gas willing to be paid for the transaction (inclusive of baseFeePerGas and maxPriorityFeePerGas)

Gas is a reference to the computation required to process the transaction by a miner. Users have to pay a fee for this computation. The gasLimit, and maxPriorityFeePerGas determine the maximum transaction fee paid to the miner. More on Gas.

The transaction object will look a little like this:

2 from: "0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8",
3 to: "0xac03bb73b6a9e108530aff4df5077c2b3d481e5a",
4 gasLimit: "21000",
5 maxFeePerGas: "300",
6 maxPriorityFeePerGas: "10",
7 nonce: "0",
8 value: "10000000000"
Показать все
📋 Копировать

But a transaction object needs to be signed using the sender's private key. This proves that the transaction could only have come from the sender and was not sent fraudulently.

An Ethereum client like Geth will handle this signing process.

Example JSON-RPC call:

2 "id": 2,
3 "jsonrpc": "2.0",
4 "method": "account_signTransaction",
5 "params": [
6 {
7 "from": "0x1923f626bb8dc025849e00f99c25fe2b2f7fb0db",
8 "gas": "0x55555",
9 "maxFeePerGas": "0x1234",
10 "maxPriorityFeePerGas": "0x1234",
11 "input": "0xabcd",
12 "nonce": "0x0",
13 "to": "0x07a565b7ed7d7a678680a4c162885bedbb695fe0",
14 "value": "0x1234"
15 }
16 ]
Показать все
📋 Копировать

Example response:

2 "jsonrpc": "2.0",
3 "id": 2,
4 "result": {
5 "raw": "0xf88380018203339407a565b7ed7d7a678680a4c162885bedbb695fe080a44401a6e4000000000000000000000000000000000000000000000000000000000000001226a0223a7c9bcf5531c99be5ea7082183816eb20cfe0bbc322e97cc5c7f71ab8b20ea02aadee6b34b45bb15bc42d9c09de4a6754e7000908da72d48cc7704971491663",
6 "tx": {
7 "nonce": "0x0",
8 "maxFeePerGas": "0x1234",
9 "maxPriorityFeePerGas": "0x1234",
10 "gas": "0x55555",
11 "to": "0x07a565b7ed7d7a678680a4c162885bedbb695fe0",
12 "value": "0x1234",
13 "input": "0xabcd",
14 "v": "0x26",
15 "r": "0x223a7c9bcf5531c99be5ea7082183816eb20cfe0bbc322e97cc5c7f71ab8b20e",
16 "s": "0x2aadee6b34b45bb15bc42d9c09de4a6754e7000908da72d48cc7704971491663",
17 "hash": "0xeba2df809e7a612a0a0d444ccfa5c839624bdc00dd29e3340d46df3870f8a30e"
18 }
19 }
Показать все
📋 Копировать
  • the raw is the signed transaction in Recursive Length Prefix (RLP) encoded form
  • the tx is the signed transaction in JSON form

With the signature hash, the transaction can be cryptographically proven that it came from the sender and submitted to the network.

Types of transactions

On Ethereum there are a few different types of transactions:

  • Regular transactions: a transaction from one wallet to another.
  • Contract deployment transactions: a transaction without a 'to' address, where the data field is used for the contract code.

On gas

As mentioned, transactions cost gas to execute. Simple transfer transactions require 21000 units of Gas.

So for Bob to send Alice 1 ETH at a baseFeePerGas of 190 gwei and maxPriorityFeePerGas of 10 gwei, Bob will need to pay the following fee:

1(190 + 10) * 21000 = 4,200,000 gwei
30.0042 ETH

Bob's account will be debited -1.0042 ETH

Alice's account will be credited +1.0 ETH

The base fee will be burned -0.00399 ETH

Miner keeps the tip +0.000210 ETH

Gas is required for any smart contract interaction too.

Diagram showing how unused gas is refunded Diagram adapted from Ethereum EVM illustrated

Any gas not used in a transaction is refunded to the user account.

Transaction lifecycle

Once the transaction has been submitted the following happens:

  1. Once you send a transaction, cryptography generates a transaction hash: 0x97d99bc7729211111a21b12c933c949d4f31684f1d6954ff477d0477538ff017
  2. The transaction is then broadcast to the network and included in a pool with lots of other transactions.
  3. A miner must pick your transaction and include it in a block in order to verify the transaction and consider it "successful".
    • You may end up waiting at this stage if the network is busy and miners aren't able to keep up.
  4. Your transaction will receive "confirmations". The number of confirmations is the number of blocks created since the block that included your transaction. The higher the number, the greater the certainty that the network processed and recognized the transaction.
    • Recent blocks may get re-organized, giving the impression the transaction was unsuccessful; however, the transaction may still be valid but included in a different block.
    • The probability of a re-organization diminishes with every subsequent block mined, i.e. the greater the number of confirmations, the more immutable the transaction is.

A visual demo

Watch Austin walk you through transactions, gas, and mining.

Typed Transaction Envelope

Ethereum originally had one format for transactions. Each transaction contained a nonce, gas price, gas limit, to address, value, data, v, r, and s. These fields are RLP-encoded, to look something like this:

RLP([nonce, gasPrice, gasLimit, to, value, data, v, r, s])

Ethereum has evolved to support multiple types of transactions to allow for new features such as access lists and EIP-1559 to be implemented without affecting legacy transaction formats.

EIP-2718: Typed Transaction Envelope defines a transaction type that is an envelope for future transaction types.

EIP-2718 is a new generalised envelope for typed transactions. In the new standard, transactions are interpreted as:

TransactionType || TransactionPayload

Where the fields are defined as:

  • TransactionType - a number between 0 and 0x7f, for a total of 128 possible transaction types.
  • TransactionPayload - an arbitrary byte array defined by the transaction type.

Further reading

Know of a community resource that helped you? Edit this page and add it!