![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
@ethereumjs/tx
Advanced tools
Package description
@ethereumjs/tx is a library for creating, signing, and serializing Ethereum transactions. It is part of the EthereumJS suite of tools and is widely used for handling Ethereum transactions in a programmatic way.
Creating a Transaction
This feature allows you to create a new Ethereum transaction by providing the necessary transaction data such as nonce, gas price, gas limit, recipient address, value, and data.
const { Transaction } = require('@ethereumjs/tx');
const txData = {
nonce: '0x00',
gasPrice: '0x09184e72a000',
gasLimit: '0x2710',
to: '0x0000000000000000000000000000000000000000',
value: '0x00',
data: '0x00'
};
const tx = Transaction.fromTxData(txData);
Signing a Transaction
This feature allows you to sign a transaction using a private key. The signed transaction can then be sent to the Ethereum network.
const { Transaction } = require('@ethereumjs/tx');
const { privateToAddress, toBuffer } = require('ethereumjs-util');
const privateKey = Buffer.from('your_private_key', 'hex');
const txData = { /* transaction data */ };
const tx = Transaction.fromTxData(txData);
const signedTx = tx.sign(privateKey);
Serializing a Transaction
This feature allows you to serialize a transaction into a format that can be sent over the network or stored for later use.
const { Transaction } = require('@ethereumjs/tx');
const txData = { /* transaction data */ };
const tx = Transaction.fromTxData(txData);
const serializedTx = tx.serialize();
The ethers.js library is a complete and compact library for interacting with the Ethereum blockchain and its ecosystem. It provides similar functionalities for creating, signing, and sending transactions, but also includes additional features like interacting with smart contracts, ENS, and more.
Web3.js is a collection of libraries that allow you to interact with a local or remote Ethereum node using HTTP, IPC, or WebSocket. It provides comprehensive functionalities for creating, signing, and sending transactions, as well as interacting with smart contracts and other Ethereum network features.
Readme
Implements schema and functions related to Ethereum's transaction. |
---|
Note: this README
reflects the state of the library from v3.0.0
onwards. See README
from the standalone repository for an introduction on the last preceeding release.
npm install @ethereumjs/tx
import { Transaction } from '@ethereumjs/tx'
const txParams = {
nonce: '0x00',
gasPrice: '0x09184e72a000',
gasLimit: '0x2710',
to: '0x0000000000000000000000000000000000000000',
value: '0x00',
data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
}
const commmon = new Common({ chain: 'mainnet' })
const tx = Transaction.fromTxData(txParams, { common })
const privateKey = Buffer.from(
'e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109',
'hex',
)
const signedTx = tx.sign(privateKey)
const serializedTx = signedTx.serialize()
Properties of a Transaction
object are frozen with Object.freeze()
which gives you enhanced security and consistency properties when working with the instantiated object. This behavior can be modified using the freeze
option in the constructor if needed.
Creating a fake tansaction for use in e.g. VM.runTx()
is simple, just overwrite getSenderAddress()
with a custom Address
like so:
import { Address } from 'ethereumjs-util'
import { Transaction } from '@ethereumjs/tx'
_getFakeTransaction(txParams: TxParams): Transaction {
const from = Address.fromString(txParams.from)
delete txParams.from
const opts = { common: this._common }
const tx = Transaction.fromTxData(txParams, opts)
const fakeTx = Object.create(tx)
// override getSenderAddress
fakeTx.getSenderAddress = () => { return from }
return fakeTx
}
The Transaction
constructor receives a parameter of an @ethereumjs/common
object that lets you specify the chain and hardfork to be used. By default, mainnet
and istanbul
will be used.
The MuirGlacier
hardfork is supported by the library since the v2.1.2
release.
Support for reduced non-zero call data gas prices from the Istanbul
hardfork
(EIP-2028) has been added to the library
along with the v2.1.1
release.
EIP-155
replay protection is activated since the spuriousDragon
hardfork. To disable it, set the hardfork to one earlier than spuriousDragon
.
See our organizational documentation for an introduction to EthereumJS
as well as information on current standards and best practices.
If you want to join for work or do improvements on the libraries have a look at our contribution guidelines.
FAQs
Implementation of the various Ethereum Transaction Types
We found that @ethereumjs/tx demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.