# ethpm

> Javascript library for EthPM (EIPs 2678 / 1319)

Latest version **0.1.0-next.32** (published 2020-12-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install ethpm
pnpm add ethpm
yarn add ethpm
bun add ethpm
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0-next.32 |
| Published | 2020-12-15 |
| First published | 2016-11-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 17 |
| Unpacked size | 473 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | g. nicholas d'andrea |
| Maintainers | tcoulter, gnidan, davidmurdoch, eggplantzzz, seesemichaelj, fainashalts, haltman, nickghita |
| Keywords | ethereum, smart-contract, package, packaging |

## Links

- npm: https://www.npmjs.com/package/ethpm
- npm.io page: https://npm.io/package/ethpm

## Dependencies (17)

- [web3](https://npm.io/package/web3.md) 1.2.2
- [bn.js](https://npm.io/package/bn.js.md) ^4.11.9
- [debug](https://npm.io/package/debug.md) ^3.2.7
- [io-ts](https://npm.io/package/io-ts.md) ^1.3.0
- [ipfsd-ctl](https://npm.io/package/ipfsd-ctl.md) ^0.42.0
- [deep-equal](https://npm.io/package/deep-equal.md) ^1.1.1
- [ethpm-spec](https://npm.io/package/ethpm-spec.md) ^3.0.0
- [ipfs-unixfs](https://npm.io/package/ipfs-unixfs.md) ^0.1.16
- [ipld-dag-pb](https://npm.io/package/ipld-dag-pb.md) ^0.14.11
- [ttypescript](https://npm.io/package/ttypescript.md) ^1.5.12
- [lodash.isequal](https://npm.io/package/lodash.isequal.md) ^4.5.0
- [ipfs-http-client](https://npm.io/package/ipfs-http-client.md) ^27.0.0
- [original-require](https://npm.io/package/original-require.md) ^1.0.1
- [source-map-support](https://npm.io/package/source-map-support.md) ^0.5.19
- [@types/lodash.isequal](https://npm.io/package/@types/lodash.isequal.md) ^4.5.5
- [json-stable-stringify](https://npm.io/package/json-stable-stringify.md) ^1.0.1
- [@zerollup/ts-transform-paths](https://npm.io/package/@zerollup/ts-transform-paths.md) ^1.7.3

## Recent versions

- 0.1.0-next.32 (latest) — 2020-12-15
- 0.1.0-next.9 (next) — 2018-11-01
- 0.1.0-next.31 — 2020-11-18
- 0.1.0-next.30 — 2020-08-31
- 0.1.0-next.29 — 2020-08-18
- 0.1.0-next.28 — 2020-08-15
- 0.0.19 — 2020-08-14
- 0.0.18 — 2020-08-14
- 0.0.17 — 2020-08-13
- 0.1.0-next.27 — 2020-08-13
- 0.1.0-next.26 — 2020-08-07
- 0.1.0-next.25 — 2020-08-03
- 0.1.0-next.24 — 2020-07-29
- 0.1.0-next.23 — 2020-07-29
- 0.1.0-next.22 — 2020-07-28
- … 36 more at https://npm.io/package/ethpm/versions

## README

ethpm.js
========

[![API Documentation](https://img.shields.io/badge/api-documentation-blue.svg)](https://ethpm.github.io/ethpm.js/index.html)
[![Build Status](https://travis-ci.org/ethpm/ethpm.js.svg?branch=master)](https://travis-ci.org/ethpm/ethpm.js)

Work in progress library for interacting with EthPM packages in
Javascript and TypeScript.

Check out a short guided tutorial [here](tutorial/README.md).

## Usage Example

```typescript
const ethpm: Session = await EthPM.configure<HasManifests>({
  manifests: "ethpm/manifests/v3",
}).connect();

const pkg = await ethpm.manifests.read(examples["wallet-with-send"]);
```

## Available APIs
There are multiple APIs that you can enable on your `ethpm` instance. Each api can be enabled by passing it's corresponding string into your `ethpm` object's configuration.

### `ethpm/manifests/v3`

Description: Enables reading & writing of V3 manifests to/from JSON and `Package` instances.

Configuration: 
```typescript
const ethpm = await EthPM.configure({
  manifests: "ethpm/manifests/v3",
}).connect();
```

Usage:
```typescript
// to generate a `Package` instance from a manifest JSON string
const package = await v3.read(manifestJson);

// to generate a manifest JSON string from a `Package` instance
const manifestJson = await v3.write(package)
```

### `ethpm/installer/truffle`

Description: Writes ethpm package assets to disk, according to the written [specification](https://ethpm-cli.readthedocs.io/en/latest/disk.html). 

Configuration: 
```typescript
const ethpm = await EthPM.configure({
  installer: "ethpm/installer/truffle",
  storage: "ethpm/storage/ipfs",
}).connect({
  workingDirectory: '/path/to/working/directory',
  ipfs: {
    host: 'ipfs.infura.io',
	port: '5001',
	protocol: 'https'
  }
});
```

Usage:
- Currently only IPFS uris are supported.

```typescript
// to install the target package in the working directory
var manifestUri = "ipfs://Qm..."
var registryAddress = "0x123abc..."
await ethpm.install(manifestUri, registryAddress)

// to install the target package under an alias in the working directory
var alias = "alternate-name"
await ethpm.install(manifestUri, registryAddress, alias)
```

### `ethpm/storage/ipfs`

Description: Reads & writes files from IPFS.

Configuration: 
```typescript
const ethpm = await EthPM.configure({
  storage: "ethpm/storage/ipfs",
}).connect({
  ipfs: {
    host: 'ipfs.infura.io',
	port: '5001',
	protocol: 'https'
  }
});
```

Usage:
```typescript
const content = "wordswordswordswordspunchline"

const uri = await ethpm.storage.write(content)

const readContent = await ethpm.storage.read(uri)

const predictedUri = await ethpm.storage.predictUri(content)

const hash = await ethpm.storage.hash(content)
```

### `ethpm/registries/web3`

Description: Publishes packages to on-chain package registries, and fetches release data from these registries.

Configuration: 
```typescript
const ethpm = await EthPM.configure({
  registries: "ethpm/registries/web3",
}).connect({
  provider: web3,
  registryAddress: '0x123abc...'
});
```

Usage:
```typescript
// list all packages
const packages = await ethpm.registries.packages()

// list all release data for a particular package's releases
const ownedReleases = await ethpm.registries.package('owned').releases()

// get manifest uri for a specific release
const manifestUri = await ethpm.registries.package('owned').release('1.0.0')

// cut a release to the connected registry
await ethpm.registries.publish('owned', '1.0.0', 'ipfs://Qm...')
```

### ethpm URI util
``` typescript
import { EthpmURI } from 'ethpm/utils/uri';

const rawUri = 'ethpm://snakecharmers.eth/owned@1.0.0'
const ethpmUri = new EthpmURI(rawUri)

ethpmUri.raw
> 'ethpm://snakecharmers.eth/owned@1.0.0'

ethpmUri.scheme
> 'ethpm'

ethpmUri.address
> 'snakecharmers.eth'

// defaults to 1 if no chain id included in rawUri
ethpmUri.chainId
> 1

ethpmUri.packageName
> 'owned'

ethpmUri.version
> '1.0.0'

ethpmUri.namespacedAsset
> ''
```

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