# web3x

> Typescript port of web3.js

Latest version **4.0.6** (published 2019-11-25) · LGPL-3.0 license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.6 |
| Published | 2019-11-25 |
| First published | 2018-10-11 |
| Weekly downloads | 0 |
| License | LGPL-3.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 18 |
| Unpacked size | 803.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 213 |
| Maintainers | xf00f |
| Keywords | Ethereum, TypeScript, API, Web3 |

## Links

- npm: https://www.npmjs.com/package/web3x
- Repository: https://github.com/xf00f/web3x
- Issues: https://github.com/xf00f/web3x/issues
- npm.io page: https://npm.io/package/web3x

## Dependencies (18)

- [ws](https://npm.io/package/ws.md) ^6.1.0
- [rlp](https://npm.io/package/rlp.md) ^2.2.3
- [utf8](https://npm.io/package/utf8.md) ^3.0.0
- [bip39](https://npm.io/package/bip39.md) ^2.5.0
- [bn.js](https://npm.io/package/bn.js.md) ^4.11.8
- [hdkey](https://npm.io/package/hdkey.md) ^1.1.0
- [tslib](https://npm.io/package/tslib.md) ^1.9.3
- [pbkdf2](https://npm.io/package/pbkdf2.md) ^3.0.17
- [elliptic](https://npm.io/package/elliptic.md) ^6.4.0
- [swarm-js](https://npm.io/package/swarm-js.md) ^0.1.39
- [@types/ws](https://npm.io/package/@types/ws.md) ^6.0.1
- [@types/node](https://npm.io/package/@types/node.md) ^10.12.18
- [randombytes](https://npm.io/package/randombytes.md) ^2.0.6
- [@types/bn.js](https://npm.io/package/@types/bn.js.md) ^4.11.2
- [idna-uts46-hx](https://npm.io/package/idna-uts46-hx.md) ^2.3.1
- [isomorphic-ws](https://npm.io/package/isomorphic-ws.md) ^4.0.1
- [browserify-aes](https://npm.io/package/browserify-aes.md) ^1.2.0
- [isomorphic-fetch](https://npm.io/package/isomorphic-fetch.md) ^2.2.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 4.0.6 (latest) — 2019-11-25
- 4.0.5 — 2019-10-26
- 4.0.4 — 2019-08-26
- 4.0.3 — 2019-06-27
- 4.0.0 — 2019-06-23
- 3.0.11 — 2019-05-22
- 3.0.10 — 2019-04-29
- 3.0.9 — 2019-04-24
- 3.0.8 — 2019-04-14
- 3.0.7 — 2019-04-01
- 3.0.6 — 2019-03-25
- 3.0.5 — 2019-03-10
- 3.0.4 — 2019-03-02
- 3.0.3 — 2019-02-23
- 3.0.2 — 2019-02-20
- … 17 more at https://npm.io/package/web3x/versions

## README

# web3x

[![Version](https://img.shields.io/npm/v/web3x.svg)](https://www.npmjs.com/package/web3x)
[![Downloads](https://img.shields.io/npm/dm/web3x.svg)](https://www.npmjs.com/package/web3x)
[![Downloads](https://img.shields.io/npm/dm/web3x-es.svg)](https://www.npmjs.com/package/web3x-es)
[![GitHub Stars](https://img.shields.io/github/stars/xf00f/web3x.svg)](https://github.com/xf00f/web3x/stargazers)
[![GitHub Issues](https://img.shields.io/github/issues/xf00f/web3x.svg)](https://github.com/xf00f/web3x/issues)
[![Coverage](https://img.shields.io/coveralls/github/xf00f/web3x/master.svg)](https://coveralls.io/github/xf00f/web3x)
[![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://github.com/xf00f/web3x/blob/master/LICENSE)

Ethereum TypeScript Client Library - for perfect types and tiny builds.

![Demo](https://user-images.githubusercontent.com/44038056/48001064-5d377d00-e0ff-11e8-994f-36d165f9124e.gif)

## Table of contents

- [Why?](#why)
- [Usage](#usage)
- [Contract type safety](#contract-type-safety)
- [The EVM provider](#the-evm-provider)
- [Differences](#differences)
- [Example projects](#example-projects)
- [Documentation](#documentation)
- [Packages](#packages)

## Why?

web3.js is a very popular Ethereum library, but:

- It has inaccurate typings and there's no way to to introduce type safety to contract code.
- It's large, weighing in at ~800k uncompressed.

web3x solves the above issues and more.

- It's pure TypeScript and generates contract types from ABIs.
- It's small, with a minimum sized contract interaction weighing in at ~150k uncompressed.
- It's expanding with additional features. For example the `EvmProvider` which provides a full inplace EVM implementation for executing contract code in your DAPP for simplified development workflows.

web3x also adopts a lean, functional design, and resolves many out the outstanding issues in the web3.js repository.

## Usage

There are two builds of the library. `web3x` uses CommonJS style imports and is best used for Node.js backends. `web3x-es` uses ES6 imports and is best used for ES6 aware tools like Webpack.

### Using inbuilt providers

The inbuilt providers are all [EIP-1193](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1193.md) compatible, and are used as follows:

```typescript
import { Address } from 'web3x-es/address';
import { WebsocketProvider } from 'web3x-es/providers';
import { Eth } from 'web3x-es/eth';
import { fromWei } from 'web3x-es/utils';

async function main() {
  const provider = new WebsocketProvider('wss://mainnet.infura.io/ws');
  const eth = new Eth(provider);
  const balance = await eth.getBalance(Address.ZERO);
  document.body.innerText = `Balance of 0 address ETH: ${fromWei(balance, 'ether')}`;
}

main().catch(console.error);
```

### Using legacy providers, e.g. MetaMask

Until MetaMask and other providers are EIP-1193 compatible, you can use them with an adapter as follows:

```typescript
import { LegacyProvider, LegacyProviderAdapter } from 'web3x-es/providers';
import { Eth } from 'web3x-es/eth';

declare const web3: {
  currentProvider: LegacyProvider;
};

const eth = new Eth(new LegacyProviderAdapter(web3.currentProvider));
```

Or a shorthand version:

```typescript
import { Eth } from 'web3x-es/eth';
const eth = Eth.fromCurrentProvider();
```

See example projects for more complex usage examples.

## Contract type safety

Interacting with contracts without type safety is tedious at best, and dangerous at worst. `web3x` provides a code generator called `web3x-codegen` to generate typings for contract ABIs either local, or remote from a simple configuration file called `contracts.json`.

Read more at [web3x-codegen](../web3x-codegen).

## The EVM provider

There is an implementation of the EVM which can be used for simplifying development workflows.

Read more at [web3x-evm](../web3x-evm).

## Differences

This is not a perfect drop in replacement for web3.js, there are differences.

- Callbacks for request/response style calls no longer supported, promises only.
- PromiEvent interface has been removed, in favour of `getTxHash()`, `getReceipt()` methods.
- Address objects must be used insead of strings. e.g. `Address.fromString('0x903ddd91207f737255ca93eb5885c0e087be0fc3')`
- Buffers are used for keys and data instead of `0x` prefixed strings.
- You should explicitly import parts of the library rather then accessing them via the web3 object.
- Sanitized some hybrid types, e.g. access wallet accounts via `wallet.get(0)` rather than `wallet[0]`.

## Example projects

Two example TypeScript projects are included, one for [webpack](../web3x-webpack-example) and one for [node.js](../web3x-node-example). They are configured to work with jest for testing. Adapting them to pure JavaScript if you don't want to use TypeScript should be trivial.

## Documentation

API documentation has not yet been ported from web3.js. For now the recommended approach for familiarising yourself with the library would be the following, in preferential order:

- Read the web3.js documentation at https://web3js.readthedocs.io/en/1.0/ to familiarise yourself with its API.
- Take a look at the example projects such as the [webpack example](../web3x-webpack-example/src/index.ts).
- Rely on your IDE and TypeScript to provide insight into the API.
- Delve into the code. It's significantly easier to follow and understand than web3.js.

## Packages

- [web3x](https://www.npmjs.com/package/web3x) (for Node.js)
- [web3x-es](https://www.npmjs.com/package/web3x-es) (for ES6 aware tools such as Webpack)

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