# ethereum-tx-decoder

> Lightweight utility for decoding function parameters from Ethereum transactions.

Latest version **3.0.0** (published 2019-09-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install ethereum-tx-decoder
pnpm add ethereum-tx-decoder
yarn add ethereum-tx-decoder
bun add ethereum-tx-decoder
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2019-09-23 |
| First published | 2017-10-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 31 |
| Author | Gregory F. J. Hogue |
| Maintainers | gfjhogue |
| Keywords | ethereum, transaction, smart, contract, abi, function, functions, parameters, params, event, events, decoder, decode, RLP, parse, parser, ethers, ethers.js, ether, eth, raw, tx |

## Links

- npm: https://www.npmjs.com/package/ethereum-tx-decoder
- Repository: https://github.com/GFJHogue/ethereum-tx-decoder
- Homepage: https://github.com/GFJHogue/ethereum-tx-decoder#readme
- Issues: https://github.com/GFJHogue/ethereum-tx-decoder/issues
- npm.io page: https://npm.io/package/ethereum-tx-decoder

## Dependencies (1)

- [ethers](https://npm.io/package/ethers.md) ^4.0.37

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2019-09-23
- 2.0.1 — 2018-05-17
- 2.0.0 — 2018-05-12
- 1.0.2 — 2017-11-19
- 1.0.1 — 2017-10-31
- 1.0.0 — 2017-10-30
- 0.0.1 — 2017-10-29
- 0.0.0 — 2017-10-29

## README

# ethereum-tx-decoder

[![npm version](https://badge.fury.io/js/ethereum-tx-decoder.svg)](https://badge.fury.io/js/ethereum-tx-decoder)[![Build Status](https://travis-ci.org/GFJHogue/ethereum-tx-decoder.svg?branch=master)](https://travis-ci.org/GFJHogue/ethereum-tx-decoder)

Lightweight utility for decoding function parameters from Ethereum transactions.

- Minimal dependencies.

- Find the exact function parameters that triggered an event.

- _[Built with ethers.js by ricmoo](https://github.com/ethers-io/ethers.js/)_.

## Usage

`npm i ethereum-tx-decoder`

### `decodeTx()`

Decode raw transactions into an Object.

```js
  var txDecoder = require('ethereum-tx-decoder');

  // transaction.raw = '0x...'
  var decodedTx = txDecoder.decodeTx(transaction.raw);
  //  {
  //    nonce:    Number
  //    gasPrice: BigNumber
  //    gasLimit: BigNumber
  //    to:       string (hex)
  //    value:    BigNumber
  //    data:     string (hex)
  //    v:        Number
  //    r:        string (hex)
  //    s:        string (hex)
  //  }
```

Need to know `from` or `chainId`? Use [`ethers.Wallet.parseTransaction()`](https://docs.ethers.io/ethers.js/html/api-wallet.html#parsing-transactions) instead.

### `class FunctionDecoder`

Decode function call data into the original parameter values.

#### New instance with [`ethers.Contract`](https://github.com/ethers-io/ethers.js/):

```js
  // contract = new Contract(address, abi, provider)
  var fnDecoder = new txDecoder.FunctionDecoder(contract.interface);
```

#### New instance with contract `abi`:

```js
  // Internally creates an ethers.Interface object.
  var fnDecoder = new txDecoder.FunctionDecoder(abi);
```

#### `decodeFn()`

```js
  fnDecoder.decodeFn(decodedTx.data);
  //  Result {
  //    ...All function parameters indexed by both name and position...
  //  }
```

Note: `decodeFn()` returns an [`Arrayish`](https://docs.ethers.io/ethers.js/html/api-utils.html#api-arrayish).

### `decodeFnFromTx()`

Shortcut for decoding a function from transaction.

```js
  fnDecoder.decodeFnFromTx(transaction.raw);
```

## BigNumber

[BigNumber Documentation (ethers.js)](https://docs.ethers.io/ethers.js/html/api-utils.html#big-numbers)

---
_Source: https://npm.io/package/ethereum-tx-decoder · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
