# @magicdust/binary-erc1155

> Binary implementation of the ERC1155 multi-token standard

Latest version **1.0.1** (published 2022-04-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @magicdust/binary-erc1155
pnpm add @magicdust/binary-erc1155
yarn add @magicdust/binary-erc1155
bun add @magicdust/binary-erc1155
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-04-12 |
| First published | 2022-04-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 32.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | MagicDust |
| Maintainers | bernardstanislas, cryptolynx, cosmic-dragon, pvilletard |
| Keywords | blockchain, ethereum, forge, smart-contracts, solidity |

## Links

- npm: https://www.npmjs.com/package/@magicdust/binary-erc1155
- Repository: https://github.com/MagicDustGG/binary-erc1155
- Homepage: https://github.com/MagicDustGG/binary-erc1155#readme
- Issues: https://github.com/MagicDustGG/binary-erc1155/issues
- npm.io page: https://npm.io/package/@magicdust/binary-erc1155

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

- 1.0.1 (latest) — 2022-04-12
- 1.0.0 — 2022-04-04

## README

# Binary ERC1155 implementation

A binary ERC1155 is an ERC1155 where an address can possess a maximum of one instance of a given token id.

Given this rule, the batch minting operation consumes on average **12 times less gas** than the general-purpose ERC1155 implementation.

```
[PASS] testBatchMintingGasConsumptionBinary(uint256) (runs: 256, μ: 102289, ~: 61374)
[PASS] testBatchMintingGasConsumptionOpenZeppelin(uint256[]) (runs: 256, μ: 1117223, ~: 635232)
[PASS] testMintingGasConsumptionBinary(uint8) (runs: 256, μ: 35630, ~: 35630)
[PASS] testMintingGasConsumptionOpenZeppelin(uint8) (runs: 256, μ: 31285, ~: 31285)
```

This contract can be used in any context where you want an address to hold a token or not, the classical usecase is for badge rewarding.

## Rationale

The need for this type of ERC1155 comes from the reward logic, where a single address can be given several badges of different types, but only one badge of a given type can be owned at a time.

## Inspiration

This implementation is based on the [OpenZeppelin ERC1155 implementation](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol) and takes advantage of the binary aspect to reduce operations' gas cost.

## Limitations

Due to the internal storage structure, the total number of different token types is limited to 256.

# Installation

## Requirements

- [Foundry](https://github.com/gakonst/foundry) (many thanks to @gakonst for the great work with Foundry)
- [Yarn](https://yarnpkg.com/)

## Install

- `yarn`

# Testing

- `yarn test`

# Benchmark

- `yarn benchmark`

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