# ethereumjs-blockchain

> A module to store and interact with blocks

Latest version **4.0.4** (published 2020-07-27) · MPL-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install ethereumjs-blockchain
pnpm add ethereumjs-blockchain
yarn add ethereumjs-blockchain
bun add ethereumjs-blockchain
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 4.0.4 |
| Published | 2020-07-27 |
| First published | 2015-08-11 |
| Weekly downloads | 0 |
| License | MPL-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 114 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 127 |
| Author | mjbecze |
| Maintainers | axic, evertonfraga, holgerd77, jwasinger, kumavis, null_radix, ralxz, sinamahmoodi |
| Keywords | ethereum, blockchain |

## Links

- npm: https://www.npmjs.com/package/ethereumjs-blockchain
- Repository: https://github.com/ethereumjs/ethereumjs-blockchain
- Homepage: https://github.com/ethereumjs/ethereumjs-blockchain#readme
- Issues: https://github.com/ethereumjs/ethereumjs-blockchain/issues
- npm.io page: https://npm.io/package/ethereumjs-blockchain

## Dependencies (10)

- [rlp](https://npm.io/package/rlp.md) ^2.2.2
- [async](https://npm.io/package/async.md) ^2.6.1
- [ethashjs](https://npm.io/package/ethashjs.md) ~0.0.7
- [level-mem](https://npm.io/package/level-mem.md) ^3.0.1
- [lru-cache](https://npm.io/package/lru-cache.md) ^5.1.1
- [semaphore](https://npm.io/package/semaphore.md) ^1.1.0
- [flow-stoplight](https://npm.io/package/flow-stoplight.md) ^1.0.0
- [ethereumjs-util](https://npm.io/package/ethereumjs-util.md) ^6.1.0
- [ethereumjs-block](https://npm.io/package/ethereumjs-block.md) ~2.2.2
- [ethereumjs-common](https://npm.io/package/ethereumjs-common.md) ^1.5.0

## Recent versions

- 4.0.4 (latest) — 2020-07-27
- 4.0.3 — 2019-12-19
- 4.0.2 — 2019-11-17
- 4.0.1 — 2019-07-01
- 4.0.0 — 2019-04-26
- 3.4.0 — 2019-02-06
- 3.3.3 — 2019-01-04
- 3.3.2 — 2018-12-22
- 3.3.1 — 2018-10-26
- 3.3.0 — 2018-10-19
- 3.2.1 — 2018-08-29
- 3.2.0 — 2018-08-13
- 3.1.0 — 2018-05-24
- 3.0.0 — 2018-05-18
- 2.1.0 — 2017-10-11
- … 20 more at https://npm.io/package/ethereumjs-blockchain/versions

## README

# SYNOPSIS

[![NPM Package](https://img.shields.io/npm/v/ethereumjs-blockchain.svg?style=flat-square)](https://www.npmjs.org/package/ethereumjs-blockchain)
[![Actions Status](https://github.com/ethereumjs/ethereumjs-blockchain/workflows/blockchain-test/badge.svg)](https://github.com/ethereumjs/ethereumjs-blockchain/actions)
[![Coverage Status](https://img.shields.io/coveralls/ethereumjs/ethereumjs-blockchain.svg?style=flat-square)](https://coveralls.io/r/ethereumjs/ethereumjs-blockchain)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ethereum/ethereumjs-lib?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) or #ethereumjs on freenode

A module to store and interact with blocks.

# INSTALL

`npm install ethereumjs-blockchain`

# API

[./docs/](./docs/README.md)

# EXAMPLE

The following is an example to iterate through an existing Geth DB (needs `level` to be installed separately).

This module performs write operations. Making a backup of your data before trying it is recommended. Otherwise, you can end up with a compromised DB state.

```javascript
const level = require('level')
const Blockchain = require('ethereumjs-blockchain').default
const utils = require('ethereumjs-util')

const gethDbPath = './chaindata' // Add your own path here. It will get modified, see remarks.
const db = level(gethDbPath)

new Blockchain({ db: db }).iterator(
  'i',
  (block, reorg, cb) => {
    const blockNumber = utils.bufferToInt(block.header.number)
    const blockHash = block.hash().toString('hex')
    console.log(`BLOCK ${blockNumber}: ${blockHash}`)
    cb()
  },
  err => console.log(err || 'Done.'),
)
```

**WARNING**: Since `ethereumjs-blockchain` is also doing write operations
on the DB for safety reasons only run this on a copy of your database, otherwise this might lead
to a compromised DB state.

# EthereumJS

See our organizational [documentation](https://ethereumjs.readthedocs.io) 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](https://ethereumjs.readthedocs.io/en/latest/contributing.html).

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