# solidity-sha3

> Solidity sha3 in Javascript

Latest version **0.4.1** (published 2016-07-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install solidity-sha3
pnpm add solidity-sha3
yarn add solidity-sha3
bun add solidity-sha3
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.1 |
| Published | 2016-07-20 |
| First published | 2016-07-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.12.0 |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | yes |
| GitHub stars | 43 |
| Author | Raine Revere |
| Maintainers | raine |
| Keywords | ethereum, solidity, sha, sha3, keccak |

## Links

- npm: https://www.npmjs.com/package/solidity-sha3
- Repository: https://github.com/raineorshine/solidity-sha3
- Homepage: https://github.com/raineorshine/solidity-sha3#readme
- Issues: https://github.com/raineorshine/solidity-sha3/issues
- npm.io page: https://npm.io/package/solidity-sha3

## Dependencies (5)

- [web3](https://npm.io/package/web3.md) ^0.16.0
- [left-pad](https://npm.io/package/left-pad.md) ^1.1.1
- [babel-cli](https://npm.io/package/babel-cli.md) *
- [babel-register](https://npm.io/package/babel-register.md) *
- [babel-preset-es2015](https://npm.io/package/babel-preset-es2015.md) *

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.4.1 (latest) — 2016-07-20
- 0.4.0 — 2016-07-20
- 0.3.0 — 2016-07-18
- 0.2.0 — 2016-07-18
- 0.1.0 — 2016-07-17
- 0.0.0 — 2016-07-17

## README

# solidity-sha3
[![npm version](https://img.shields.io/npm/v/solidity-sha3.svg)](https://npmjs.org/package/solidity-sha3)
[![Build Status](https://travis-ci.org/raineorshine/solidity-sha3.svg?branch=master)](https://travis-ci.org/raineorshine/solidity-sha3)

`web3.sha3` doesn't always match the behavior of `sha3` in Solidity. This one does.

- Hashes integers (default size: `uint256`)
- Hashes tightly-packed arguments
- Supports hex strings and BigNumber instances

## Install

```sh
$ npm install --save solidity-sha3
```

## Usage

```js
import sha3 from 'solidity-sha3'

sha3('a') // 0x3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb
sha3('0x0a') // 0x0ef9d8f8804d174666011a394cab7901679a8944d24249fd148a6a36071151f8
sha3(1) // 0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6
sha3(-1) // 0xa9c584056064687e149968cbab758a3376d22aedc6a55823d1b3ecbee81b8fb9
sha3(new BigNumber('100')) // 0x26700e13983fefbd9cf16da2ed70fa5c6798ac55062a4803121a869731e308d2
sha3('a', 1) // 0xb5cafab5b83d18303877bb912b2d66ca18ab7390cfd9be8a2e66cc5096e0ea02
```

You can also hash a value at a specific size:

```js
import { sha3withsize } from 'solidity-sha3'

// same as sha3(uint32(1)) in Solidity
sha3withsize(1, 32) // 0x51f81bcdfc324a0dff2b5bec9d92e21cbebc4d5e29d3a3d30de3e03fbeab8d7f

// same as sha3(1) in Solidity
sha3withsize(1, 8) // 0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2
```

Be aware that strings will be converted into hex by default. You can use `sha3num` to explicitly pad and hash a string as a number. This is useful for Wei that is not a BigNumber instance:

```js
import { sha3num } from 'solidity-sha3'

// same as sha3(uint(100 ether)) in Solidity
sha3num(web3.toWei(100)) // c7cc234d21c9cfbd4632749fd77669e7ae72f5241ce5895e410c45185a469273

// otherwise, it would convert the value '100000000000000000000' to '0x56bc75e2d63100000' and then hash that
sha3(web3.toWei(100)) // 0x44bc2093d8a26b279e2eecbfdcb9cc0b960c2141b83a29dce25f2a18c2653bfa
```

## License

ISC © [Raine Revere](https://github.com/raineorshine)

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