# @0xcert/ethereum-utils

> General Ethereum utility module with helper functions for the Ethereum blockchain.

Latest version **2.1.1** (published 2021-03-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @0xcert/ethereum-utils
pnpm add @0xcert/ethereum-utils
yarn add @0xcert/ethereum-utils
bun add @0xcert/ethereum-utils
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2021-03-15 |
| First published | 2018-06-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 52.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 339 |
| Maintainers | xpepermint, moman |
| Keywords | 0xcert, framework, protocol, asset, value, values, currency, token, non-fungible, fungible, erc-721, erc-20, blockchain, javascript, typescript, nodejs, vuejs, nuxtjs, npm, libraries, smart-contract, ethereum, zxc |

## Links

- npm: https://www.npmjs.com/package/@0xcert/ethereum-utils
- Repository: https://github.com/0xcert/framework
- Homepage: https://github.com/0xcert/framework#readme
- Issues: https://github.com/0xcert/framework/issues
- npm.io page: https://npm.io/package/@0xcert/ethereum-utils

## Dependencies (1)

- [ethers](https://npm.io/package/ethers.md) 4.0.47

## 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

- 2.1.1 (latest) — 2021-03-15
- 2.1.0 — 2021-01-14
- 2.0.3 — 2020-08-12
- 2.0.2 — 2020-05-04
- 2.0.1 — 2020-03-06
- 2.0.1-beta0 — 2020-03-05
- 2.0.0 — 2020-03-02
- 2.0.0-beta5 — 2020-02-22
- 2.0.0-beta4 — 2020-02-19
- 2.0.0-beta3 — 2020-02-05
- 2.0.0-beta2 — 2020-01-30
- 2.0.0-beta1 — 2020-01-20
- 2.0.0-beta — 2020-01-17
- 2.0.0-alpha17 — 2020-01-14
- 2.0.0-alpha16 — 2020-01-13
- … 57 more at https://npm.io/package/@0xcert/ethereum-utils/versions

## README

<img src="../../assets/cover-sub.png" />

> General Ethereum utility module with helper functions for the Ethereum blockchain.

The [0xcert Framework](https://docs.0xcert.org) is a free and open-source JavaScript library that provides tools for building powerful decentralized applications. Please refer to the [official documentation](https://docs.0xcert.org) for more details.

This module is one of the bricks of the [0xcert Framework](https://docs.0xcert.org). It's written with [TypeScript](https://www.typescriptlang.org) and it's actively maintained. The source code is available on [GitHub](https://github.com/0xcert/framework) where you can also find our [issue tracker](https://github.com/0xcert/framework/issues).

# Ethereum Utilities

This module wraps several useful Ethereum functions which will be useful through the 0xcert Framework. Currently supported are these functions and classes from [ethers.js](https://github.com/ethers-io/ethers.js):

## ABI coder

This converts the value to and from the packed [Ethereum ABI encoding](https://solidity.readthedocs.io/en/develop/abi-spec.html#formal-specification-of-the-encoding).

* `encodeParameters`(types: `any`, values: `Array<any>`): `string`
* `decodeParameters`(types: `any`, data: `any`): `any`

**Encoding example:**

```ts
import { decodeParameters, encodeParameters } from '0xcert/ethereum-utils/abi';

const types = ['tuple(uint256, uint256[])'];
const values = [[ 42, [ 45 ] ]];
const encodedValues = encodeParameters(types, values);
```

**Decoding example:**

```ts
import { decodeParameters, encodeParameters } from '0xcert/ethereum-utils/abi';

const types = ['tuple(uint256, uint256[])'];
const encoded = '0x' +
  '0000000000000000000000000000000000000000000000000000000000000020' +
  '000000000000000000000000000000000000000000000000000000000000002a' +
  '0000000000000000000000000000000000000000000000000000000000000040' +
  '0000000000000000000000000000000000000000000000000000000000000001' +
  '000000000000000000000000000000000000000000000000000000000000002d';
const values = decodeParameters(types, values);
```

## Big umbers

Here is a basic example adapted from [the ethers.js documentation](https://docs.ethers.io/ethers.js/html/api-utils.html?highlight=bignumberify#big-numbers).

```ts
import { bigNumberify } from '0xcert/ethereum-utils/big-number';

let gasPriceWei = bigNumberify("20902747399");
let gasLimit = bigNumberify(3000000);

let maxCostWei = gasPriceWei.mul(gasLimit)
console.log("Max Cost: " + maxCostWei.toString());
// "Max Cost: 62708242197000000"

console.log("Number: " + maxCostWei.toNumber());
// throws an Error, the value is too large for JavaScript to handle safely
```

## Address normalization

The ethers.js [address normalization function](https://docs.ethers.io/ethers.js/html/api-utils.html?highlight=getaddress#addresses) implements [EIP-55 Mixed-case checksum address encoding](https://eips.ethereum.org/EIPS/eip-55).


```ts
import { getAddress } from '0xcert/ethereum-utils/normalize-address';

let zxcTokenAddress = '0x83e2be8d114f9661221384b3a50d24b96a5653f5';
let zxcTokenAddressNormalized = normalizeAddress(zxcToenAddress);
// 0x83e2BE8d114F9661221384B3a50d24B96a5653F5
```

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