# @openzeppelin/network

> An easy to use and reliable library that provides one line access to Web3 API.

Latest version **0.4.3** (published 2020-08-05) · MIT license · 0 weekly downloads

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

## Install

```sh
npm install @openzeppelin/network
pnpm add @openzeppelin/network
yarn add @openzeppelin/network
bun add @openzeppelin/network
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.4.3 |
| Published | 2020-08-05 |
| First published | 2019-07-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 198.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 42 |
| Author | Igor Yalovoy |
| Maintainers | frangio, jcarpanelli, nventuro, spalladino, ylv.io |
| Keywords | react, react-hooks, hooks, ethereum, solidity, javascript, web3, context, frontend, dapp, metamask, infura |

## Links

- npm: https://www.npmjs.com/package/@openzeppelin/network
- Repository: https://github.com/OpenZeppelin/openzeppelin-network.js
- Homepage: https://github.com/OpenZeppelin/openzeppelin-network.js#readme
- Issues: https://github.com/OpenZeppelin/openzeppelin-network.js/issues
- npm.io page: https://npm.io/package/@openzeppelin/network

## Dependencies (4)

- [web3](https://npm.io/package/web3.md) ^1.2.1
- [fast-deep-equal](https://npm.io/package/fast-deep-equal.md) ^2.0.1
- [ethereumjs-wallet](https://npm.io/package/ethereumjs-wallet.md) ^0.6.3
- [@openzeppelin/gsn-provider](https://npm.io/package/@openzeppelin/gsn-provider.md) ^0.1.10

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.4.3 (latest) — 2020-08-05
- 0.4.2 — 2020-03-11
- 0.4.1 — 2020-02-20
- 0.4.0 — 2020-02-03
- 0.3.0 — 2020-01-28
- 0.2.10 — 2019-10-02
- 0.2.9 — 2019-08-28
- 0.2.8 — 2019-08-28
- 0.2.7 — 2019-08-17
- 0.2.6 — 2019-08-14
- 0.2.5 — 2019-08-07
- 0.2.4 — 2019-08-07
- 0.2.3 — 2019-08-07
- 0.2.2 — 2019-08-07
- 0.1.2 — 2019-07-25
- … 2 more at https://npm.io/package/@openzeppelin/network/versions

## README

:warning: This project is **deprecated**. We are no longer actively developing new features nor addressing issues. Read [here](https://forum.openzeppelin.com/t/doubling-down-in-security/2712) for more info, and reach out if you are interested in taking over maintenance. We suggest looking into [web3-react](https://github.com/NoahZinsmeister/web3-react) for a popular alternative to this project.

# openzeppelin-network.js
[![CircleCI](https://circleci.com/gh/OpenZeppelin/openzeppelin-network.js.svg?style=shield)](https://circleci.com/gh/OpenZeppelin/openzeppelin-network.js)
[![npm (scoped)](https://img.shields.io/npm/v/@openzeppelin/network)](https://www.npmjs.com/package/@openzeppelin/network)

**One line access to Web3 in your dApp.**

 * Hides various Web3 providers behind common API.
 * One line access to the Web3 providers (Metamask, Infura, Geth, Portis and etc).
 * Supports multiple Web3 providers within the same app.
 * First class support of meta-txs.
 * React integration using hooks.
 * Network, accounts, and connection changed events for all web3 providers.
 * Will fire events even for HTTP and forcefully terminated providers.

## Overview

### Installation

```console
npm install @openzeppelin/network
```

### Usage

#### With React Hooks
Import the library:

```javascript
import { useWeb3Injected, useWeb3Network, useEphemeralKey } from '@openzeppelin/network/react';
```

Get Web3Context with React Hooks inside functional component:

```javascript
const injected = useWeb3Injected();
const local = useWeb3Network('http://127.0.0.1:8545');
```

Use `Web3Context` to get fresh data:

```javascript
const { accounts, networkId, networkName, providerName, lib, connected } = web3Context;
```

Network.js will re-render component when network, accounts or connetion state change.

To use GSN with any hook specify GSN as an option, providing a signing key:

```typescript
const local = useWeb3Network('http://127.0.0.1:8545', {
  gsn: { signKey: useEphemeralKey() }
});
```

#### With Vanilla Javascript
Import the library:

```javascript
import { fromInjected, fromConnection } from '@openzeppelin/network';
```

Get `Web3Context`:

```javascript
const injected = await fromInjected();
const local = await fromConnection('http://127.0.0.1:8545');
```

To use GSN include a `gsn` option, including a signing key:

```typescript
const local = await fromConnection('http://127.0.0.1:8545', {
  gsn: { signKey: ephemeral() }
});
```

Use `Web3Context` to get fresh data immediately:

```javascript
const { accounts, networkId, networkName, providerName, lib, connected } = web3Context;
```

Subscribe to events to get notified:

```javascript
function updateNetwork(networkId, networkName) {}
function updateAccounts(accounts) {}
function updateConnection(connected) {}

web3Context.on(Web3Context.NetworkIdChangedEventName, updateNetwork);
web3Context.on(Web3Context.AccountsChangedEventName, updateAccounts);
web3Context.on(Web3Context.ConnectionChangedEventName, updateConnection);
```

Unsubscribe from events once you don't need them:

```javascript
web3Context.off(Web3Context.NetworkIdChangedEventName, updateNetwork);
web3Context.off(Web3Context.AccountsChangedEventName, updateAccounts);
web3Context.off(Web3Context.ConnectionChangedEventName, updateConnection);

```

## Learn More

 * Try it out on the [GSN Starter Kit](https://docs.openzeppelin.com/starter-kits/gsnkit): run `npx @openzeppelin/cli unpack gsn` in a new directory and follow the instructions.
 * For detailed usage information, take a look at the [API Reference](https://docs.openzeppelin.com/network-js/api).

## License

Released under the MIT License.

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