@ethereumjs/tx / FeeMarketEIP1559Transaction
Typed transaction with a new gas fee market mechanism
BaseTransaction
<FeeMarketEIP1559
>
↳ FeeMarketEIP1559Transaction
• 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<TransactionType.FeeMarketEIP1559\>.constructor
tx/src/eip1559Transaction.ts:150
• Readonly
AccessListJSON: AccessList
tx/src/eip1559Transaction.ts:46
• Readonly
accessList: AccessListBytes
tx/src/eip1559Transaction.ts:45
• cache: TransactionCache
BaseTransaction.cache
• Readonly
chainId: bigint
tx/src/eip1559Transaction.ts:44
• Readonly
common: Common
BaseTransaction.common
tx/src/eip1559Transaction.ts:50
• Readonly
data: Uint8Array
BaseTransaction.data
• Readonly
gasLimit: bigint
BaseTransaction.gasLimit
• Readonly
maxFeePerGas: bigint
tx/src/eip1559Transaction.ts:48
• Readonly
maxPriorityFeePerGas: bigint
tx/src/eip1559Transaction.ts:47
• Readonly
nonce: bigint
BaseTransaction.nonce
• Optional
Readonly
r: bigint
BaseTransaction.r
• Optional
Readonly
s: bigint
BaseTransaction.s
• Optional
Readonly
to: Address
BaseTransaction.to
• Optional
Readonly
v: bigint
BaseTransaction.v
• Readonly
value: bigint
BaseTransaction.value
• get
type(): TransactionType
Returns the transaction type.
Note: legacy txs will return tx type 0
.
BaseTransaction.type
▸ addSignature(v
, r
, s
, convertV?
): FeeMarketEIP1559Transaction
Name | Type | Default value |
---|---|---|
v |
bigint |
undefined |
r |
bigint | Uint8Array |
undefined |
s |
bigint | Uint8Array |
undefined |
convertV |
boolean |
false |
BaseTransaction.addSignature
tx/src/eip1559Transaction.ts:319
▸ errorStr(): string
Return a compact error string representation of the object
string
BaseTransaction.errorStr
tx/src/eip1559Transaction.ts:367
▸ getBaseFee(): bigint
The minimum amount of gas the tx must have (DataFee + TxFee + Creation Fee)
bigint
BaseTransaction.getBaseFee
▸ getDataFee(): bigint
The amount of gas paid for the data in this tx
bigint
BaseTransaction.getDataFee
tx/src/eip1559Transaction.ts:205
▸ getEffectivePriorityFee(baseFee
): bigint
Returns the minimum of calculated priority fee (from maxFeePerGas and baseFee) and maxPriorityFeePerGas
Name | Type | Description |
---|---|---|
baseFee |
bigint |
Base fee retrieved from block |
bigint
BaseTransaction.getEffectivePriorityFee
tx/src/eip1559Transaction.ts:213
▸ getHashedMessageToSign(): Uint8Array
Returns the hashed serialized unsigned tx, 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.
Uint8Array
BaseTransaction.getHashedMessageToSign
tx/src/eip1559Transaction.ts:291
▸ getMessageToSign(): Uint8Array
Returns the raw serialized unsigned tx, 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() // use this for the HW wallet input
Uint8Array
BaseTransaction.getMessageToSign
tx/src/eip1559Transaction.ts:280
▸ getMessageToVerifySignature(): Uint8Array
Computes a sha3-256 hash which can be used to verify the signature
Uint8Array
BaseTransaction.getMessageToVerifySignature
tx/src/eip1559Transaction.ts:308
▸ getSenderAddress(): Address
Returns the sender’s address
Address
BaseTransaction.getSenderAddress
▸ getSenderPublicKey(): Uint8Array
Returns the public key of the sender
Uint8Array
BaseTransaction.getSenderPublicKey
tx/src/eip1559Transaction.ts:315
▸ getUpfrontCost(baseFee?
): bigint
The up front amount that an account must have for this transaction to be valid
Name | Type | Default value | Description |
---|---|---|---|
baseFee |
bigint |
BIGINT_0 |
The base fee of the block (will be set to 0 if not provided) |
bigint
BaseTransaction.getUpfrontCost
tx/src/eip1559Transaction.ts:221
▸ getValidationErrors(): string
[]
Validates the transaction signature and minimum gas requirements.
string
[]
an array of error strings
BaseTransaction.getValidationErrors
▸ hash(): Uint8Array
Computes a sha3-256 hash of the serialized tx.
This method can only be used for signed txs (it throws otherwise). Use getMessageToSign to get a tx hash for the purpose of signing.
Uint8Array
BaseTransaction.hash
tx/src/eip1559Transaction.ts:301
▸ isSigned(): boolean
boolean
BaseTransaction.isSigned
▸ isValid(): boolean
Validates the transaction signature and minimum gas requirements.
boolean
true if the transaction is valid, false otherwise
BaseTransaction.isValid
▸ raw(): FeeMarketEIP1559TxValuesArray
Returns a Uint8Array Array of the raw Bytes of the EIP-1559 transaction, in order.
Format: [chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
accessList, signatureYParity, signatureR, signatureS]
Use serialize to add a transaction to a block with Block.fromValuesArray.
For an unsigned tx this method uses the empty Bytes values for the
signature parameters v
, r
and s
for encoding. For an EIP-155 compliant
representation for external signing use getMessageToSign.
FeeMarketEIP1559TxValuesArray
BaseTransaction.raw
tx/src/eip1559Transaction.ts:238
▸ serialize(): Uint8Array
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.
Uint8Array
BaseTransaction.serialize
tx/src/eip1559Transaction.ts:265
▸ 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 |
Uint8Array |
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 Capabilities
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
tx/src/eip1559Transaction.ts:351
▸ verifySignature(): boolean
Determines if the signature is valid
boolean
BaseTransaction.verifySignature
▸ 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 |
Uint8Array |
opts |
TxOptions |
tx/src/eip1559Transaction.ts:72
▸ 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 providedName | Type |
---|---|
txData |
FeeMarketEIP1559TxData |
opts |
TxOptions |
tx/src/eip1559Transaction.ts:62
▸ 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 |
FeeMarketEIP1559TxValuesArray |
opts |
TxOptions |