@ethereumjs/tx v3.0.0-beta.1
Pre-releaseATTENTION: This is a pre-release and only meant to be used for testing purposes.
Do not use in production!
Feedback is extremely welcome, please use the beta.1
Releases feedback issue #923 or our Discord channel.
New Package Name
Attention! This new version is part of a series of EthereumJS releases all moving to a new scoped package name format. In this case the library is renamed as follows:
ethereumjs-tx
->@ethereumjs/tx
Please update your library references accordingly or install with:
npm i @ethereumjs/tx
Major Refactoring - Breaking Changes
This release is a major refactoring of the transaction library to simplify and strengthen its code base. Refactoring work has been done along PR #812 and PR #887.
New Constructor Params
The constructor used to accept a varying amount of options but now has the following shape:
Transaction(
nonce: BN,
gasPrice: BN,
gasLimit: BN,
to: Address | undefined,
value: BN,
data: Buffer,
v?: BN,
r?: BN,
s?: BN,
opts?: TxOptions
)
Initializing from other data types is assisted with new static factory helpers fromTxData
, fromRlpSerializedTx
, and fromValuesArray
.
Examples:
// Initializing from serialized data
const s1 = tx1.serialize().toString('hex')
const tx = Transaction.fromRlpSerializedTx(toBuffer('0x' + s1))
// Initializing with object
const txData = {
gasPrice: 1000,
gasLimit: 10000000,
value: 42,
}
const tx = Transaction.fromTxData(txData)
// Initializing from array of 0x-prefixed strings.
// First, convert to array of Buffers.
const arr = txFixture.raw.map(toBuffer)
const tx = Transaction.fromValuesArray(arr)
Learn more about the full API in the docs.
Immutability
The returned transaction is now frozen and immutable. To work with a maliable transaction, copy it with const fakeTx = Object.create(tx)
.
from
The tx.from
alias was removed, please use const from = tx.getSenderAddress()
.
Message to sign
Getting a message to sign has been changed from calling tx.hash(false)
to tx.getMessageToSign()
.
Fake Transaction
The FakeTransaction
class was removed since its functionality can now be implemented with less code. To create a fake tansaction for use in e.g. VM.runTx()
overwrite getSenderAddress
with your own Address
. See a full example in the section in the README.
New Default Hardfork
Breaking: The default HF on the library has been updated from petersburg
to instanbul
, see PR #906.
The HF setting is now automatically taken from the HF set for Common.DEAULT_HARDFORK
, see PR #863.
Dual ES5 and ES2017 Builds
We significantly updated our internal tool and CI setup along the work on PR #913 with an update to ESLint
from TSLint
for code linting and formatting and the introduction of a new build setup.
Packages now target ES2017
for Node.js builds (the main
entrypoint from package.json
) and introduce a separate ES5
build distributed along using the browser
directive as an entrypoint, see PR #921. This will result in performance benefits for Node.js consumers, see here for a releated discussion.
Other Changes
Changes and Refactoring