Skip to content

Latest commit

 

History

History
829 lines (456 loc) · 17.2 KB

LegacyTransaction.md

File metadata and controls

829 lines (456 loc) · 17.2 KB

@ethereumjs/tx / LegacyTransaction

Class: LegacyTransaction

An Ethereum non-typed (legacy) transaction

Hierarchy

  • BaseTransaction<Legacy>

    LegacyTransaction

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&gt;.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:273


errorStr

errorStr(): string

Return a compact error string representation of the object

Returns

string

Overrides

BaseTransaction.errorStr

Defined in

tx/src/legacyTransaction.ts:363


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:234


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:226


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:203


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:258


getSenderAddress

getSenderAddress(): Address

Returns the sender's address

Returns

Address

Inherited from

BaseTransaction.getSenderAddress

Defined in

tx/src/baseTransaction.ts:272


getSenderPublicKey

getSenderPublicKey(): Uint8Array

Returns the public key of the sender

Returns

Uint8Array

Overrides

BaseTransaction.getSenderPublicKey

Defined in

tx/src/legacyTransaction.ts:269


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:241


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:251


isSigned

isSigned(): boolean

Returns

boolean

Inherited from

BaseTransaction.isSigned

Defined in

tx/src/baseTransaction.ts:247


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:163


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:186


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:290


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:216


toJSON

toJSON(): JsonTx

Returns an object with the JSON representation of the transaction.

Returns

JsonTx

Overrides

BaseTransaction.toJSON

Defined in

tx/src/legacyTransaction.ts:306


verifySignature

verifySignature(): boolean

Determines if the signature is valid

Returns

boolean

Inherited from

BaseTransaction.verifySignature

Defined in

tx/src/baseTransaction.ts:259


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:

  • All parameters are optional and have some basic default values

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