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
|
17 | const EthereumTx = require('ethereumjs-tx').Transaction
|
18 | const privateKey = Buffer.from(
|
19 | 'e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109',
|
20 | 'hex',
|
21 | )
|
22 |
|
23 | const 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
|
33 | const tx = new EthereumTx(txParams, { chain: 'mainnet', hardfork: 'petersburg' })
|
34 | tx.sign(privateKey)
|
35 | const serializedTx = tx.serialize()
|
36 | ```
|
37 |
|
38 | # Chain and Hardfork Support
|
39 |
|
40 | The `Transaction` and `FakeTransaction` constructors receives a second parameter that lets you specify the chain and hardfork
|
41 | to be used. By default, `mainnet` and `petersburg` will be used.
|
42 |
|
43 | There are two ways of customizing these. The first one, as shown in the previous section, is by
|
44 | using an object with `chain` and `hardfork` names. You can see en example of this in [./examples/ropsten-tx.ts](./examples/ropsten-tx.ts).
|
45 |
|
46 | The 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 |
|
50 | The `MuirGlacier` hardfork is supported by the library since the `v2.1.2` release.
|
51 |
|
52 | ## Istanbul Support
|
53 |
|
54 | Support 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
|
56 | along 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
|
61 | hardfork in the `Transaction`'s constructor.
|
62 |
|
63 | # API
|
64 |
|
65 | [./docs/](./docs/README.md)
|
66 |
|
67 | # EthereumJS
|
68 |
|
69 | See our organizational [documentation](https://ethereumjs.readthedocs.io) for an introduction to `EthereumJS` as well as information on current standards and best practices.
|
70 |
|
71 | If 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)>)
|