@ethereumjs/tx / FeeMarketEIP1559Transaction
Typed transaction with a new gas fee market mechanism
- TransactionType: 2
- EIP: EIP-1559
-
BaseTransaction
<FeeMarketEIP1559Transaction
>↳
FeeMarketEIP1559Transaction
- AccessListJSON
- accessList
- chainId
- common
- data
- gasLimit
- maxFeePerGas
- maxPriorityFeePerGas
- nonce
- r
- s
- to
- v
- value
- _processSignature
- errorStr
- getBaseFee
- getDataFee
- getMessageToSign
- getMessageToVerifySignature
- getSenderAddress
- getSenderPublicKey
- getUpfrontCost
- hash
- isSigned
- raw
- serialize
- sign
- supports
- toCreationAddress
- toJSON
- validate
- verifySignature
- fromRlpSerializedTx
- fromSerializedTx
- fromTxData
- fromValuesArray
• new FeeMarketEIP1559Transaction(txData
, opts?
)
This constructor takes the values, validates them, assigns them and freezes the object.
It is not recommended to use this constructor directly. Instead use the static factory methods to assist in creating a Transaction object from varying data types.
Name | Type |
---|---|
txData |
FeeMarketEIP1559TxData |
opts |
TxOptions |
BaseTransaction<FeeMarketEIP1559Transaction>.constructor
• Readonly
AccessListJSON: AccessList
• Readonly
accessList: AccessListBuffer
• Readonly
chainId: BN
• Readonly
common: default
BaseTransaction.common
• Readonly
data: Buffer
BaseTransaction.data
• Readonly
gasLimit: BN
BaseTransaction.gasLimit
• Readonly
maxFeePerGas: BN
• Readonly
maxPriorityFeePerGas: BN
• Readonly
nonce: BN
BaseTransaction.nonce
• Optional
Readonly
r: BN
BaseTransaction.r
• Optional
Readonly
s: BN
BaseTransaction.s
• Optional
Readonly
to: Address
BaseTransaction.to
• Optional
Readonly
v: BN
BaseTransaction.v
• Readonly
value: BN
BaseTransaction.value
• get
senderR(): undefined
| BN
EIP-2930 alias for r
deprecated
use r
instead
undefined
| BN
• get
senderS(): undefined
| BN
EIP-2930 alias for s
deprecated
use s
instead
undefined
| BN
• get
transactionType(): number
Alias for {@link BaseTransaction.type}
deprecated
Use type
instead
number
BaseTransaction.transactionType
• get
type(): number
Returns the transaction type.
Note: legacy txs will return tx type 0
.
number
BaseTransaction.type
• get
yParity(): undefined
| BN
EIP-2930 alias for v
deprecated
use v
instead
undefined
| BN
▸ _processSignature(v
, r
, s
): FeeMarketEIP1559Transaction
Name | Type |
---|---|
v |
number |
r |
Buffer |
s |
Buffer |
BaseTransaction._processSignature
▸ errorStr(): string
Return a compact error string representation of the object
string
BaseTransaction.errorStr
▸ getBaseFee(): BN
The minimum amount of gas the tx must have (DataFee + TxFee + Creation Fee)
BN
BaseTransaction.getBaseFee
▸ getDataFee(): BN
The amount of gas paid for the data in this tx
BN
BaseTransaction.getDataFee
▸ getMessageToSign(hashMessage?
): Buffer
Returns the serialized unsigned tx (hashed or raw), which can be used to sign the transaction (e.g. for sending to a hardware wallet).
Note: in contrast to the legacy tx the raw message format is already serialized and doesn't need to be RLP encoded any more.
const serializedMessage = tx.getMessageToSign(false) // use this for the HW wallet input
Name | Type | Default value | Description |
---|---|---|---|
hashMessage |
boolean |
true |
Return hashed message if set to true (default: true) |
Buffer
BaseTransaction.getMessageToSign
▸ getMessageToVerifySignature(): Buffer
Computes a sha3-256 hash which can be used to verify the signature
Buffer
BaseTransaction.getMessageToVerifySignature
▸ getSenderAddress(): Address
Returns the sender's address
Address
BaseTransaction.getSenderAddress
▸ getSenderPublicKey(): Buffer
Returns the public key of the sender
Buffer
BaseTransaction.getSenderPublicKey
▸ getUpfrontCost(baseFee?
): BN
The up front amount that an account must have for this transaction to be valid
Name | Type | Description |
---|---|---|
baseFee |
BN |
The base fee of the block (will be set to 0 if not provided) |
BN
BaseTransaction.getUpfrontCost
▸ hash(): Buffer
Computes a sha3-256 hash of the serialized tx.
This method can only be used for signed txs (it throws otherwise). Use FeeMarketEIP1559Transaction.getMessageToSign to get a tx hash for the purpose of signing.
Buffer
BaseTransaction.hash
▸ isSigned(): boolean
boolean
BaseTransaction.isSigned
▸ raw(): FeeMarketEIP1559ValuesArray
Returns a Buffer Array of the raw Buffers of the EIP-1559 transaction, in order.
Format: [chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, signatureYParity, signatureR, signatureS]
Use FeeMarketEIP1559Transaction.serialize to add a transaction to a block with {@link Block.fromValuesArray}.
For an unsigned tx this method uses the empty Buffer values for the
signature parameters v
, r
and s
for encoding. For an EIP-155 compliant
representation for external signing use FeeMarketEIP1559Transaction.getMessageToSign.
BaseTransaction.raw
▸ serialize(): Buffer
Returns the serialized encoding of the EIP-1559 transaction.
Format: 0x02 || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, signatureYParity, signatureR, signatureS])
Note that in contrast to the legacy tx serialization format this is not valid RLP any more due to the raw tx type preceding and concatenated to the RLP encoding of the values.
Buffer
BaseTransaction.serialize
▸ sign(privateKey
): FeeMarketEIP1559Transaction
Signs a transaction.
Note that the signed tx is returned as a new object, use as follows:
const signedTx = tx.sign(privateKey)
Name | Type |
---|---|
privateKey |
Buffer |
BaseTransaction.sign
▸ supports(capability
): boolean
Checks if a tx type defining capability is active on a tx, for example the EIP-1559 fee market mechanism or the EIP-2930 access list feature.
Note that this is different from the tx type itself, so EIP-2930 access lists can very well be active on an EIP-1559 tx for example.
This method can be useful for feature checks if the tx type is unknown (e.g. when instantiated with the tx factory).
See Capabilites
in the types
module for a reference
on all supported capabilities.
Name | Type |
---|---|
capability |
Capability |
boolean
BaseTransaction.supports
▸ toCreationAddress(): boolean
If the tx's to
is to the creation address
boolean
BaseTransaction.toCreationAddress
▸ toJSON(): JsonTx
Returns an object with the JSON representation of the transaction
BaseTransaction.toJSON
▸ validate(): boolean
Checks if the transaction has the minimum amount of gas required (DataFee + TxFee + Creation Fee).
boolean
BaseTransaction.validate
▸ validate(stringError
): boolean
Name | Type |
---|---|
stringError |
false |
boolean
BaseTransaction.validate
▸ validate(stringError
): string
[]
Name | Type |
---|---|
stringError |
true |
string
[]
BaseTransaction.validate
▸ verifySignature(): boolean
Determines if the signature is valid
boolean
BaseTransaction.verifySignature
▸ Static
fromRlpSerializedTx(serialized
, opts?
): FeeMarketEIP1559Transaction
Instantiate a transaction from the serialized tx. (alias of FeeMarketEIP1559Transaction.fromSerializedTx)
Note: This means that the Buffer should start with 0x01.
deprecated
this constructor alias is deprecated and will be removed
in favor of the FeeMarketEIP1559Transaction.fromSerializedTx constructor
Name | Type |
---|---|
serialized |
Buffer |
opts |
TxOptions |
▸ Static
fromSerializedTx(serialized
, opts?
): FeeMarketEIP1559Transaction
Instantiate a transaction from the serialized tx.
Format: 0x02 || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, signatureYParity, signatureR, signatureS])
Name | Type |
---|---|
serialized |
Buffer |
opts |
TxOptions |
▸ Static
fromTxData(txData
, opts?
): FeeMarketEIP1559Transaction
Instantiate a transaction from a data dictionary.
Format: { chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, v, r, s }
Notes:
chainId
will be set automatically if not provided- All parameters are optional and have some basic default values
Name | Type |
---|---|
txData |
FeeMarketEIP1559TxData |
opts |
TxOptions |
▸ Static
fromValuesArray(values
, opts?
): FeeMarketEIP1559Transaction
Create a transaction from a values array.
Format: [chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, signatureYParity, signatureR, signatureS]
Name | Type |
---|---|
values |
FeeMarketEIP1559ValuesArray |
opts |
TxOptions |