目录
Txn Type: 0 (Legacy transactions, 遗留事务)
Txn Type: 1 (Access list transactions, 接入列表事务) EIP-2930
以太坊链上上主要有3中交易类型
Txn Type: 0 (Legacy)
Txn Type: 1
Txn Type: 2 (EIP-1559)
主要在使用的是0和2类型,1类型在实际的交易中很少看到,在etherscan也可以看出一些端倪。
Txn Type: 0 (Legacy transactions, 遗留事务)
Transactions with type
0x0
are legacy transactions that use the transaction format existing before typed transactions were introduced in EIP-2718. They contain the parametersnonce
,gasPrice
,gasLimit
,to
,value
,data
,v
,r
, ands
. Legacy transactions don’t use access lists or incorporate EIP-1559 fee market changes.
引用的英文文档已经说的很清楚了, type 0x0
是EIP-2718议案提出之前使用的类型。在该议案之前并没有一个的成文标准,交易都遵守一个事实上的以太坊交易格式,即
每个交易包括一个随机数(nonce)、gas价格、gas极限、目的地址、value、数据、v、r、和s。这些字段是RLP编码的,如下所示:
RLP([nonce, gasPrice, gasLimit, to, value, data, v, r, s])
EIP-2718议案
EIP-155复杂性看旧交易格式的现有问题
增加的复杂性的一个很好的例子是EIP155,它通过在交易中使用链ID来引入了回放保护(reply protection)。向交易参数中添加一个新字段将会破坏向后兼容性(backwards compatibility),因为链ID被编码到交易签名(v)的恢复参数(v)中。使用EIP-2718,我们可以简单地创建一个新的交易类型,以维护向后兼容性。
EIP-2718规定
首先要说明的是,EIP-2718议案并非是针对的某一个具体的Txn Type的标准,而是一个更加顶层和抽象的标准,是由开发人员迈卡·佐尔图(Micah·Zoltu)创建的。具体如下:
TransactionType || TransactionPayload
其中,这些字段被定义为:
交易类型:介于和0x7f之间的数字,总共有128个可能的交易类型。
交易有效负载:由交易类型定义的任意字节数组。
这些字段连接组合形成类型化交易。该标准没有描述交易有效负载的格式;它可以是任何任意的字节系列,由新的交易类型(例如,RLP、SSZ等)定义的编码器进行编码。选择简单的字节连接是因为读取一个字节数组的第一个字节,而不需要任何库或工具:你不需要一个RLP或SSZ解析器来检查交易类型。
EIP-2718优势
1. 减少不必要的复杂性。该议案支持引入交易类型,而不是在现有交易格式中引入不必要的复杂性,而且使不同的以太坊工具(客户端、库)来区分不同的交易变得更容易
2. 向后兼容性和原始交易。EIP-2718采用完全向后兼容模式,这意味着任何现有的工具、库、(硬件)钱包和交易都可以使用它,但他们将无法使用EIP-2718提供的新“功能”以及使用它的标准。旧的交易格式(现在称为原始交易)对于以太坊网络上的新交易仍然有效。
新交易类型的最大数目为0x7f,被选为维持这些旧交易的向后兼容性。RLP编码的交易总是以一个为l的字节开头,参数大于或等于0xc0,因此类型化交易永远不会与旧交易发生冲突,并且只需检查第一个字节,就可以区分类型化交易和旧交易。
Txn Type: 1 (Access list transactions, 接入列表事务) EIP-2930
Transactions with type
0x1
are transactions introduced in EIP-2930. They contain, along with the legacy parameters, anaccessList
parameter, which specifies an array of addresses and storage keys that the transaction plans to access (an access list). Access list transactions must specify an access list, and they don’t incorporate EIP-1559 fee market changes.
为了缓解EIP-2929带来的Gas增长问题,柏林引进了EIP-2930。EIP-2930允许用户在提交交易时指定一个“访问列表”,让交易显示其计划访问的状态,以便使用低于Eip-2929中指定的Gas Fee。
Txn Type: 2 EIP-1559
Transactions with type
0x2
are transactions introduced in EIP-1559, included in Ethereum's London fork. EIP-1559 addresses the network congestion and overpricing of transaction fees caused by the historical fee market, in which users send transactions specifying a gas price bid using thegasPrice
parameter, and miners choose transactions with the highest bids.EIP-1559 transactions don’t specify
gasPrice
, and instead use an in-protocol, dynamically changing base fee per gas. At each block, the base fee per gas is adjusted to address network congestion as measured by a gas target.EIP-1559 transactions contain, along with the
accessList
parameter and legacy parameters except forgasPrice,
amaxPriorityFeePerGas
parameter, which specifies the maximum fee the sender is willing to pay per gas above the base fee (the maximum priority fee per gas), and amaxFeePerGas
parameter, which specifies the maximum total fee (base fee + priority fee) the sender is willing to pay per gas.An EIP-1559 transaction always pays the base fee of the block it’s included in, and it pays a priority fee as priced by
maxPriorityFeePerGas
or, if the base fee per gas +maxPriorityFeePerGas
exceedsmaxFeePerGas
, it pays a priority fee as priced bymaxFeePerGas
minus the base fee per gas. The base fee is burned, and the priority fee is paid to the miner that included the transaction. A transaction’s priority fee per gas incentivizes miners to include the transaction over other transactions with lower priority fees per gas.
在EIP-1559中,gas的工作方式发生了显著的变化。不再向矿工支付全部gas,而是燃烧一部分gas。我们不详细介绍EIP-1559的所有变化,但它确实指定了一种新的交易格式:
0x02 || RLP([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, signatureYParity, signatureR, signatureS])
最显著的变化是:
Gas价格已被“每个Gas最高优先费用”和“每个Gas最高费用”所替代。
链ID是单独编码,而不是包含在签名v值中。这本质上用一个更简单的执行取代了EIP-155。
签名v值现在是一个简单的奇偶校验位(“签名Y奇偶校验”),它是或1,这取决于应该使用椭圆曲线上的哪个点。
EIP-1559还提供了一种基于EIP-2930来指定访问列表的方法。这可以降低交易的gas成本。
由于EIP-1559对Gas费用的工作方式发生了重大变化,因此它与原始交易并不直接兼容。为了保持向后兼容性,EIP-1559描述了一种将原始交易升级到EIP-1559兼容的交易的方法。它通过使用原始Gas价格作为每个Gas的最高优先费用和最高Gas费用来实现这一点。
EIP-2711议案(目前并未确定交易类型)
目标解决痛点 :对于原始元交易(meta transactions)、分批交易(batch transactions)、即将到期的交易到目前为止仍一直需要智能合约,由智能合约专门支持对应的交易。
EIP-2711使得原生元交易(称为赞助交易)和批交易成为可能,而不需要智能合约。一种新的交易格式被定义。交易如下:
0x0n || RLP([...SenderPayload, ...SenderSignature, ...GasPayerPayload, ...GasPayerSignature])
即EIP-2711包括一个(可选的)有效载荷和gas支付人的签名。该账户将用于支付交易中的gas费用。例如,可以从一个地址发送ERC-20代币,而不需要该地址持有任何ETH。发送方有效载荷、签名等是基于交易子类型定义的。例如,对于交易类型为1的交易,发送方有效载荷被定义为:
[1, ChildTransaction[], nonce, ChainId, ValidUntil, gasLimit, gasPrice]
子交易( Child Transaction )被定义为:发送地址、值、数据。这使得可以在单个交易中指定多个地址、值和数据。例如,这可以用于在单个交易中调用ERC-20的批准和转移。
参考
Transaction types - Infura Docs
一文了解以太坊上的新交易类型|迈卡·佐尔图|智能合约|以太坊|eip
qkl456.com/233115.html
https://eips.ETHereum.org/eips/eip-2929
https://eips.ETHereum.org/eips/eip-2930
以太坊柏林升级包括哪些内容?
What is EIP-1559? How Will It Change Ethereum? | ConsenSys