Transaction
Hierarchy
- BaseTransaction<Transaction>
- Transaction
Index
Constructors
Properties
Accessors
Methods
Constructors
publicconstructor
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
Returns Transaction
Properties
publicreadonlycommon
publicreadonlydata
publicreadonlygasLimit
publicreadonlygasPrice
publicreadonlynonce
publicoptionalreadonlyr
publicoptionalreadonlys
publicoptionalreadonlyto
publicoptionalreadonlyv
publicreadonlyvalue
Accessors
publictype
Returns the transaction type.
Note: legacy txs will return tx type
0
.Returns number
Methods
publicerrorStr
Return a compact error string representation of the object
Returns string
publicgetBaseFee
The minimum amount of gas the tx must have (DataFee + TxFee + Creation Fee)
Returns bigint
publicgetDataFee
The amount of gas paid for the data in this tx
Returns bigint
publicgetMessageToSign
Returns the unsigned tx (hashed or raw), 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 { bufArrToArr } from '../util'
import { RLP } from '../rlp'
const message = tx.getMessageToSign(false)
const serializedMessage = RLP.encode(message) // use this for the HW wallet inputParameters
hashMessage: false
Return hashed message if set to true (default: true)
Returns Uint8Array[]
publicgetMessageToVerifySignature
Computes a sha3-256 hash which can be used to verify the signature
Returns Uint8Array
publicgetSenderAddress
Returns the sender's address
Returns Address
publicgetSenderPublicKey
Returns the public key of the sender
Returns Uint8Array
publicgetUpfrontCost
The up front amount that an account must have for this transaction to be valid
Returns bigint
publichash
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
publicisSigned
Returns boolean
publicraw
Returns a Uint8Array Array of the raw Uint8Arrays 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 Uint8Array values for the signature parameters
v
,r
ands
. For an EIP-155 compliant representation have a look at Transaction.getMessageToSign.Returns TxValuesArray
publicserialize
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
ands
for encoding. For an EIP-155 compliant representation for external signing use Transaction.getMessageToSign.Returns Uint8Array
publicsign
Signs a transaction.
Note that the signed tx is returned as a new object, use as follows:
const signedTx = tx.sign(privateKey)
Parameters
privateKey: Uint8Array
Returns Transaction
publicsupports
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 thetypes
module for a reference on all supported capabilities.Parameters
capability: Capability
Returns boolean
publictoCreationAddress
If the tx's
to
is to the creation addressReturns boolean
publictoJSON
Returns an object with the JSON representation of the transaction.
Returns JsonTx
publicvalidate
Checks if the transaction has the minimum amount of gas required (DataFee + TxFee + Creation Fee).
Returns boolean
publicverifySignature
Determines if the signature is valid
Returns boolean
publicstaticfromSerializedTx
Instantiate a transaction from the serialized tx.
Format:
rlp([nonce, gasPrice, gasLimit, to, value, data, v, r, s])
Parameters
serialized: Uint8Array
opts: TxOptions = {}
Returns Transaction
publicstaticfromTxData
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
Returns Transaction
publicstaticfromValuesArray
Create a transaction from a values array.
Format:
[nonce, gasPrice, gasLimit, to, value, data, v, r, s]
Parameters
values: TxValuesArray
opts: TxOptions = {}
Returns Transaction
An Ethereum non-typed (legacy) transaction