UNPKG

3.18 kBMarkdownView Raw
1# SYNOPSIS
2
3[![NPM Package](https://img.shields.io/npm/v/ethereumjs-tx.svg?style=flat-square)](https://www.npmjs.org/package/ethereumjs-tx)
4[![Actions Status](https://github.com/ethereumjs/ethereumjs-tx/workflows/tx-test/badge.svg)](https://github.com/ethereumjs/ethereumjs-tx/actions)
5[![Coverage Status](https://img.shields.io/coveralls/ethereumjs/ethereumjs-tx.svg?style=flat-square)](https://coveralls.io/r/ethereumjs/ethereumjs-tx)
6[![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs-lib.svg?style=flat-square)](https://gitter.im/ethereum/ethereumjs-lib) or #ethereumjs on freenode
7
8# INSTALL
9
10`npm install ethereumjs-tx`
11
12# USAGE
13
14- [example](https://github.com/ethereumjs/ethereumjs-tx/blob/master/examples/transactions.ts)
15
16```javascript
17const EthereumTx = require('ethereumjs-tx').Transaction
18const privateKey = Buffer.from(
19 'e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109',
20 'hex',
21)
22
23const txParams = {
24 nonce: '0x00',
25 gasPrice: '0x09184e72a000',
26 gasLimit: '0x2710',
27 to: '0x0000000000000000000000000000000000000000',
28 value: '0x00',
29 data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
30}
31
32// The second parameter is not necessary if these values are used
33const tx = new EthereumTx(txParams, { chain: 'mainnet', hardfork: 'petersburg' })
34tx.sign(privateKey)
35const serializedTx = tx.serialize()
36```
37
38# Chain and Hardfork Support
39
40The `Transaction` and `FakeTransaction` constructors receives a second parameter that lets you specify the chain and hardfork
41to be used. By default, `mainnet` and `petersburg` will be used.
42
43There are two ways of customizing these. The first one, as shown in the previous section, is by
44using an object with `chain` and `hardfork` names. You can see en example of this in [./examples/ropsten-tx.ts](./examples/ropsten-tx.ts).
45
46The second option is by passing the option `common` set to an instance of [ethereumjs-common](https://github.com/ethereumjs/ethereumjs-common)' Common. This is specially useful for custom networks or chains/hardforks not yet supported by `ethereumjs-common`. You can see en example of this in [./examples/custom-chain-tx.ts](./examples/custom-chain-tx.ts).
47
48## MuirGlacier Support
49
50The `MuirGlacier` hardfork is supported by the library since the `v2.1.2` release.
51
52## Istanbul Support
53
54Support for reduced non-zero call data gas prices from the `Istanbul` hardfork
55([EIP-2028](https://eips.ethereum.org/EIPS/eip-2028)) has been added to the library
56along with the `v2.1.1` release.
57
58# EIP-155 support
59
60`EIP-155` replay protection is activated since the `spuriousDragon` hardfork. To disable it, set the
61hardfork in the `Transaction`'s constructor.
62
63# API
64
65[./docs/](./docs/README.md)
66
67# EthereumJS
68
69See our organizational [documentation](https://ethereumjs.readthedocs.io) for an introduction to `EthereumJS` as well as information on current standards and best practices.
70
71If you want to join for work or do improvements on the libraries have a look at our [contribution guidelines](https://ethereumjs.readthedocs.io/en/latest/contributing.html).
72
73# LICENSE
74
75[MPL-2.0](<https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2)>)