Socket
Book a DemoInstallSign in
Socket

@magicdust/binary-erc1155

Package Overview
Dependencies
Maintainers
4
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@magicdust/binary-erc1155

Binary implementation of the ERC1155 multi-token standard

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
4
Created
Source

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 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 (many thanks to @gakonst for the great work with Foundry)
  • Yarn

Install

  • yarn

Testing

  • yarn test

Benchmark

  • yarn benchmark

Keywords

blockchain

FAQs

Package last updated on 12 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.