ethereumjs-monorepo

@ethereumjs/tx / LegacyTransaction

Class: LegacyTransaction

An Ethereum non-typed (legacy) transaction

Hierarchy

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

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.

Parameters

Name Type
txData LegacyTxData
opts TxOptions

Overrides

BaseTransaction<TransactionType.Legacy\>.constructor

Defined in

tx/src/legacyTransaction.ts:113

Properties

cache

cache: TransactionCache

Inherited from

BaseTransaction.cache

Defined in

tx/src/baseTransaction.ts:54


common

Readonly common: Common

Overrides

BaseTransaction.common

Defined in

tx/src/legacyTransaction.ts:42


data

Readonly data: Uint8Array

Inherited from

BaseTransaction.data

Defined in

tx/src/baseTransaction.ts:46


gasLimit

Readonly gasLimit: bigint

Inherited from

BaseTransaction.gasLimit

Defined in

tx/src/baseTransaction.ts:43


gasPrice

Readonly gasPrice: bigint

Defined in

tx/src/legacyTransaction.ts:40


nonce

Readonly nonce: bigint

Inherited from

BaseTransaction.nonce

Defined in

tx/src/baseTransaction.ts:42


r

Optional Readonly r: bigint

Inherited from

BaseTransaction.r

Defined in

tx/src/baseTransaction.ts:49


s

Optional Readonly s: bigint

Inherited from

BaseTransaction.s

Defined in

tx/src/baseTransaction.ts:50


to

Optional Readonly to: Address

Inherited from

BaseTransaction.to

Defined in

tx/src/baseTransaction.ts:44


v

Optional Readonly v: bigint

Inherited from

BaseTransaction.v

Defined in

tx/src/baseTransaction.ts:48


value

Readonly value: bigint

Inherited from

BaseTransaction.value

Defined in

tx/src/baseTransaction.ts:45

Accessors

type

get type(): TransactionType

Returns the transaction type.

Note: legacy txs will return tx type 0.

Returns

TransactionType

Inherited from

BaseTransaction.type

Defined in

tx/src/baseTransaction.ts:121

Methods

addSignature

addSignature(v, r, s, convertV?): LegacyTransaction

Parameters

Name Type Default value
v bigint undefined
r bigint | Uint8Array undefined
s bigint | Uint8Array undefined
convertV boolean false

Returns

LegacyTransaction

Overrides

BaseTransaction.addSignature

Defined in

tx/src/legacyTransaction.ts:277


errorStr

errorStr(): string

Return a compact error string representation of the object

Returns

string

Overrides

BaseTransaction.errorStr

Defined in

tx/src/legacyTransaction.ts:367


getBaseFee

getBaseFee(): bigint

The minimum amount of gas the tx must have (DataFee + TxFee + Creation Fee)

Returns

bigint

Inherited from

BaseTransaction.getBaseFee

Defined in

tx/src/baseTransaction.ts:176


getDataFee

getDataFee(): bigint

The amount of gas paid for the data in this tx

Returns

bigint

Overrides

BaseTransaction.getDataFee

Defined in

tx/src/legacyTransaction.ts:238


getEffectivePriorityFee

getEffectivePriorityFee(baseFee?): bigint

Parameters

Name Type
baseFee? bigint

Returns

bigint

Overrides

BaseTransaction.getEffectivePriorityFee

Defined in

tx/src/legacyTransaction.ts:150


getHashedMessageToSign

getHashedMessageToSign(): Uint8Array

Returns the hashed serialized unsigned tx, which can be used to sign the transaction (e.g. for sending to a hardware wallet).

Returns

Uint8Array

Overrides

BaseTransaction.getHashedMessageToSign

Defined in

tx/src/legacyTransaction.ts:230


getMessageToSign

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

Returns

Uint8Array[]

Overrides

BaseTransaction.getMessageToSign

Defined in

tx/src/legacyTransaction.ts:207


getMessageToVerifySignature

getMessageToVerifySignature(): Uint8Array

Computes a sha3-256 hash which can be used to verify the signature

Returns

Uint8Array

Overrides

BaseTransaction.getMessageToVerifySignature

Defined in

tx/src/legacyTransaction.ts:262


getSenderAddress

getSenderAddress(): Address

Returns the sender’s address

Returns

Address

Inherited from

BaseTransaction.getSenderAddress

Defined in

tx/src/baseTransaction.ts:279


getSenderPublicKey

getSenderPublicKey(): Uint8Array

Returns the public key of the sender

Returns

Uint8Array

Overrides

BaseTransaction.getSenderPublicKey

Defined in

tx/src/legacyTransaction.ts:273


getUpfrontCost

getUpfrontCost(): bigint

The up front amount that an account must have for this transaction to be valid

Returns

bigint

Overrides

BaseTransaction.getUpfrontCost

Defined in

tx/src/legacyTransaction.ts:245


getValidationErrors

getValidationErrors(): string[]

Validates the transaction signature and minimum gas requirements.

Returns

string[]

an array of error strings

Inherited from

BaseTransaction.getValidationErrors

Defined in

tx/src/baseTransaction.ts:149


hash

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.

Returns

Uint8Array

Overrides

BaseTransaction.hash

Defined in

tx/src/legacyTransaction.ts:255


isSigned

isSigned(): boolean

Returns

boolean

Inherited from

BaseTransaction.isSigned

Defined in

tx/src/baseTransaction.ts:254


isValid

isValid(): boolean

Validates the transaction signature and minimum gas requirements.

Returns

boolean

true if the transaction is valid, false otherwise

Inherited from

BaseTransaction.isValid

Defined in

tx/src/baseTransaction.ts:167


raw

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.

Returns

LegacyTxValuesArray

Overrides

BaseTransaction.raw

Defined in

tx/src/legacyTransaction.ts:167


serialize

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.

Returns

Uint8Array

Overrides

BaseTransaction.serialize

Defined in

tx/src/legacyTransaction.ts:190


sign

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)

Parameters

Name Type
privateKey Uint8Array

Returns

LegacyTransaction

Inherited from

BaseTransaction.sign

Defined in

tx/src/baseTransaction.ts:297


supports

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.

Parameters

Name Type
capability Capability

Returns

boolean

Inherited from

BaseTransaction.supports

Defined in

tx/src/baseTransaction.ts:141


toCreationAddress

toCreationAddress(): boolean

If the tx’s to is to the creation address

Returns

boolean

Inherited from

BaseTransaction.toCreationAddress

Defined in

tx/src/baseTransaction.ts:223


toJSON

toJSON(): JsonTx

Returns an object with the JSON representation of the transaction.

Returns

JsonTx

Overrides

BaseTransaction.toJSON

Defined in

tx/src/legacyTransaction.ts:310


verifySignature

verifySignature(): boolean

Determines if the signature is valid

Returns

boolean

Inherited from

BaseTransaction.verifySignature

Defined in

tx/src/baseTransaction.ts:266


fromSerializedTx

Static fromSerializedTx(serialized, opts?): LegacyTransaction

Instantiate a transaction from the serialized tx.

Format: rlp([nonce, gasPrice, gasLimit, to, value, data, v, r, s])

Parameters

Name Type
serialized Uint8Array
opts TxOptions

Returns

LegacyTransaction

Defined in

tx/src/legacyTransaction.ts:62


fromTxData

Static fromTxData(txData, opts?): LegacyTransaction

Instantiate a transaction from a data dictionary.

Format: { nonce, gasPrice, gasLimit, to, value, data, v, r, s }

Notes:

Parameters

Name Type
txData LegacyTxData
opts TxOptions

Returns

LegacyTransaction

Defined in

tx/src/legacyTransaction.ts:53


fromValuesArray

Static fromValuesArray(values, opts?): LegacyTransaction

Create a transaction from a values array.

Format: [nonce, gasPrice, gasLimit, to, value, data, v, r, s]

Parameters

Name Type
values LegacyTxValuesArray
opts TxOptions

Returns

LegacyTransaction

Defined in

tx/src/legacyTransaction.ts:77