@ethereumjs/tx / LegacyTransaction
An Ethereum non-typed (legacy) transaction
BaseTransaction
<Legacy
>
↳ LegacyTransaction
• new LegacyTransaction(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 |
LegacyTxData |
opts |
TxOptions |
BaseTransaction<TransactionType.Legacy\>.constructor
tx/src/legacyTransaction.ts:113
• cache: TransactionCache
BaseTransaction.cache
• Readonly
common: Common
BaseTransaction.common
tx/src/legacyTransaction.ts:42
• Readonly
data: Uint8Array
BaseTransaction.data
• Readonly
gasLimit: bigint
BaseTransaction.gasLimit
• Readonly
gasPrice: bigint
tx/src/legacyTransaction.ts:40
• 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?
): LegacyTransaction
Name | Type | Default value |
---|---|---|
v |
bigint |
undefined |
r |
bigint | Uint8Array |
undefined |
s |
bigint | Uint8Array |
undefined |
convertV |
boolean |
false |
BaseTransaction.addSignature
tx/src/legacyTransaction.ts:277
▸ errorStr(): string
Return a compact error string representation of the object
string
BaseTransaction.errorStr
tx/src/legacyTransaction.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/legacyTransaction.ts:238
▸ getEffectivePriorityFee(baseFee?
): bigint
Name | Type |
---|---|
baseFee? |
bigint |
bigint
BaseTransaction.getEffectivePriorityFee
tx/src/legacyTransaction.ts:150
▸ getHashedMessageToSign(): Uint8Array
Returns the hashed serialized unsigned tx, which can be used to sign the transaction (e.g. for sending to a hardware wallet).
Uint8Array
BaseTransaction.getHashedMessageToSign
tx/src/legacyTransaction.ts:230
▸ getMessageToSign(): Uint8Array
[]
Returns the raw unsigned tx, which can be used to sign the transaction (e.g. for sending to a hardware wallet).
Note: the raw message message format for the legacy tx is not RLP encoded and you might need to do yourself with:
import { RLP } from '@ethereumjs/rlp'
const message = tx.getMessageToSign()
const serializedMessage = RLP.encode(message)) // use this for the HW wallet input
Uint8Array
[]
BaseTransaction.getMessageToSign
tx/src/legacyTransaction.ts:207
▸ getMessageToVerifySignature(): Uint8Array
Computes a sha3-256 hash which can be used to verify the signature
Uint8Array
BaseTransaction.getMessageToVerifySignature
tx/src/legacyTransaction.ts:262
▸ getSenderAddress(): Address
Returns the sender’s address
Address
BaseTransaction.getSenderAddress
▸ getSenderPublicKey(): Uint8Array
Returns the public key of the sender
Uint8Array
BaseTransaction.getSenderPublicKey
tx/src/legacyTransaction.ts:273
▸ getUpfrontCost(): bigint
The up front amount that an account must have for this transaction to be valid
bigint
BaseTransaction.getUpfrontCost
tx/src/legacyTransaction.ts:245
▸ 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 Transaction.getMessageToSign to get a tx hash for the purpose of signing.
Uint8Array
BaseTransaction.hash
tx/src/legacyTransaction.ts:255
▸ 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(): LegacyTxValuesArray
Returns a Uint8Array Array of the raw Bytes of the legacy transaction, in order.
Format: [nonce, gasPrice, gasLimit, to, value, data, v, r, s]
For legacy txs this is also the correct format to add transactions
to a block with Block.fromValuesArray (use the serialize()
method
for typed txs).
For an unsigned tx this method returns the empty Bytes values
for the signature parameters v
, r
and s
. For an EIP-155 compliant
representation have a look at Transaction.getMessageToSign.
LegacyTxValuesArray
BaseTransaction.raw
tx/src/legacyTransaction.ts:167
▸ serialize(): Uint8Array
Returns the serialized encoding of the legacy transaction.
Format: rlp([nonce, gasPrice, gasLimit, to, value, data, v, r, s])
For an unsigned tx this method uses the empty Uint8Array values for the
signature parameters v
, r
and s
for encoding. For an EIP-155 compliant
representation for external signing use Transaction.getMessageToSign.
Uint8Array
BaseTransaction.serialize
tx/src/legacyTransaction.ts:190
▸ sign(privateKey
): LegacyTransaction
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/legacyTransaction.ts:310
▸ verifySignature(): boolean
Determines if the signature is valid
boolean
BaseTransaction.verifySignature
▸ Static
fromSerializedTx(serialized
, opts?
): LegacyTransaction
Instantiate a transaction from the serialized tx.
Format: rlp([nonce, gasPrice, gasLimit, to, value, data, v, r, s])
Name | Type |
---|---|
serialized |
Uint8Array |
opts |
TxOptions |
tx/src/legacyTransaction.ts:62
▸ Static
fromTxData(txData
, opts?
): LegacyTransaction
Instantiate a transaction from a data dictionary.
Format: { nonce, gasPrice, gasLimit, to, value, data, v, r, s }
Notes:
Name | Type |
---|---|
txData |
LegacyTxData |
opts |
TxOptions |
tx/src/legacyTransaction.ts:53
▸ Static
fromValuesArray(values
, opts?
): LegacyTransaction
Create a transaction from a values array.
Format: [nonce, gasPrice, gasLimit, to, value, data, v, r, s]
Name | Type |
---|---|
values |
LegacyTxValuesArray |
opts |
TxOptions |