# web3.storage

> API client for web3.storage

Latest version **4.5.5** (published 2023-07-19) · (Apache-2.0 OR MIT) license · 0 weekly downloads

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

## Install

```sh
npm install web3.storage
pnpm add web3.storage
yarn add web3.storage
bun add web3.storage
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 4.5.5 |
| Published | 2023-07-19 |
| First published | 2021-07-09 |
| Weekly downloads | 0 |
| License | (Apache-2.0 OR MIT) |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 16 |
| Unpacked size | 1.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 503 |
| Maintainers | alanshaw, olizilla, vascosantos, ipfsbot, it-dag-house |

## Links

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

## Dependencies (16)

- [cborg](https://npm.io/package/cborg.md) ^1.8.0
- [w3name](https://npm.io/package/w3name.md) ^1.0.6
- [p-retry](https://npm.io/package/p-retry.md) ^4.5.0
- [carbites](https://npm.io/package/carbites.md) ^1.0.6
- [ipfs-car](https://npm.io/package/ipfs-car.md) ^0.7.0
- [@ipld/car](https://npm.io/package/@ipld/car.md) ^3.1.4
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^3.0.0
- [@web-std/blob](https://npm.io/package/@web-std/blob.md) ^3.0.4
- [@web-std/file](https://npm.io/package/@web-std/file.md) ^3.0.2
- [libp2p-crypto](https://npm.io/package/libp2p-crypto.md) ^0.21.0
- [@web-std/fetch](https://npm.io/package/@web-std/fetch.md) ^4.1.2
- [files-from-path](https://npm.io/package/files-from-path.md) ^0.2.4
- [throttled-queue](https://npm.io/package/throttled-queue.md) ^2.1.2
- [streaming-iterables](https://npm.io/package/streaming-iterables.md) ^6.2.0
- [browser-readablestream-to-it](https://npm.io/package/browser-readablestream-to-it.md) ^1.0.3
- [@web3-storage/parse-link-header](https://npm.io/package/@web3-storage/parse-link-header.md) ^3.1.0

## Recent versions

- 4.5.5 (latest) — 2023-07-19
- 4.5.4 — 2023-02-28
- 4.4.0 — 2022-08-22
- 4.3.0 — 2022-06-23
- 4.2.0 — 2022-04-19
- 4.1.0 — 2022-04-19
- 4.0.0 — 2022-03-24
- 3.5.7 — 2022-03-07
- 3.5.6 — 2022-03-01
- 3.5.5 — 2022-02-24
- 3.5.4 — 2022-02-03
- 3.5.3 — 2022-01-11
- 3.5.2 — 2021-12-27
- 3.5.1 — 2021-12-06
- 3.5.0 — 2021-11-30
- … 14 more at https://npm.io/package/web3.storage/versions

## README

<h1 align="center">⁂<br/>web3.storage</h1>
<p align="center">The JavaScript API client for <a href="https://web3.storage">https://web3.storage</a></p>

## Getting started

Install the package using npm

```console
npm install web3.storage
```

## Usage

The code below shows how you create a new web3.storage api client, and use it to `put` your files to web3, and `get` them back again.

Sign in to <https://web3.storage>, create an API token, and use it in place of `API_TOKEN` when creating your instance of the client.

```js
import { Web3Storage } from 'web3.storage'

// Construct with token and endpoint
const client = new Web3Storage({ token: API_TOKEN })

const fileInput = document.querySelector('input[type="file"]')

// Pack files into a CAR and send to web3.storage
const rootCid = await client.put(fileInput.files) // Promise<CIDString>

// Get info on the Filecoin deals that the CID is stored in
const info = await client.status(rootCid) // Promise<Status | undefined>

// Fetch and verify files from web3.storage
const res = await client.get(rootCid) // Promise<Web3Response | null>
const files = await res.files() // Promise<Web3File[]>

for (const file of files) {
  console.log(`${file.cid} ${file.name} ${file.size}`)
}
```

### Mutability

Management of mutable name records with IPNS has now moved to the [w3name client](https://github.com/web3-storage/w3name/blob/main/packages/client).

## Testing
Run `npm test` to test the ESM code, CJS, and in the browser via `playwright-test`. 100% test coverage is required by the `hundreds` module.

To test in individual environments, you'll need two terminal windows open. In the first, start up the mock API by running `npm run mock:api`. In the second, you can then run `npm run test:web`, `npm run test:esm` or `npm run test:cjs`.

Tests are written in `mocha` and use a mock API server to assert functionality. When adding a new method to the client, add a `test/<method>.spec.js` test suite to go with it.

The mock api is built with [`smoke`](https://github.com/sinedied/smoke) _file-based mock server_. You add a files to the `test/mocks/api` directory, and the [file name](https://github.com/sinedied/smoke#file-naming) determines which API enpoint you are mocking. You can provide a `.json` for a static response, or a `.js` file to add some logic to the mock.

- `post_car.js` handles `POST /car` requests.
- `get_car#@cid.js` handes `GET /car/:cid` requests. The cid part of the path is provided to the mock as `params.cid`.

Add more mocks as required.

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