All Projects → fiveoutofnine → on-mint-generation

fiveoutofnine / on-mint-generation

Licence: AGPL-3.0 license
An example of an ERC721 token with efficient on-mint generation from 7 traits (taken from BAYC; see details below).

Programming Languages

solidity
1140 projects
python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to on-mint-generation

etherscan-python
A minimal, yet complete, python API for Etherscan.io.
Stars: ✭ 335 (+544.23%)
Mutual labels:  erc721
Awesome NFTs
A curated collection about NFTs - by bt3gl
Stars: ✭ 42 (-19.23%)
Mutual labels:  erc721
CryptoKitties
A simple implementation of CryptoKitties on Ethereum using ERC721 token.
Stars: ✭ 32 (-38.46%)
Mutual labels:  erc721
opensea-arb-nft20
🧸 💸 Detects arbitrage opportunities for ERC-721 tokens between OpenSea and NFT20.
Stars: ✭ 42 (-19.23%)
Mutual labels:  erc721
niftygate
Drop-in Access Control via NFT Ownership
Stars: ✭ 61 (+17.31%)
Mutual labels:  erc721
Nix
Nix - NFT Decentralised Exchange Smart Contracts
Stars: ✭ 40 (-23.08%)
Mutual labels:  erc721
Simple-Game-ERC-721-Token-Template
🔮 Very Simple ERC-721 Smart Contract Template to create your own ERC-721 Tokens on the Ethereum Blockchain, with many customizable Options 🔮
Stars: ✭ 83 (+59.62%)
Mutual labels:  erc721
Cryptocurrency Icons
A set of icons for all the main cryptocurrencies and altcoins, in a range of styles and sizes.
Stars: ✭ 2,116 (+3969.23%)
Mutual labels:  erc721
nftfy-v1-core
A decentralized protocol for NFT fractionalization
Stars: ✭ 62 (+19.23%)
Mutual labels:  erc721
Wallet3
A secure mobile wallet for web3
Stars: ✭ 13 (-75%)
Mutual labels:  erc721
cyberevents
The protocol for EVENTs and TICKETs
Stars: ✭ 16 (-69.23%)
Mutual labels:  erc721
ethereum-kit-ios
Comprehensive EVM SDK (ex: Ethereum, Binance Smart Chain) for iOS, implemented on Swift. Create wallets, watch wallets (read-only), sync transactions, filter transactions by type (erc20, bep20, swap transactions etc.), swap using native DEX protocols, easily extendable to work with custom smart contracts, and full support for EIP1159.
Stars: ✭ 148 (+184.62%)
Mutual labels:  erc721
ethereum-dex
Decentralized exchange implementation for the 0xcert protocol on the Ethereum blockchain.
Stars: ✭ 18 (-65.38%)
Mutual labels:  erc721
rarity-analyser
Cool Rarity is an open source package for easy rarity score calculation with ERC721 NFT metadata collection. It was born in punkscape 01 rarity analyser hackathon.
Stars: ✭ 82 (+57.69%)
Mutual labels:  erc721
nft-contracts
Open-source NFT contracts used by buildship.dev
Stars: ✭ 60 (+15.38%)
Mutual labels:  erc721
fingernft
FingerNFT是一款开源NFT市场,兼容Opensea、Rarible。
Stars: ✭ 1,827 (+3413.46%)
Mutual labels:  erc721
opensea-scraper
Scrapes nft floor prices and additional information from opensea. Used for https://nftfloorprice.info
Stars: ✭ 129 (+148.08%)
Mutual labels:  erc721
nft-swap-sdk
Ethereum's missing p2p NFT and token swap library for web3 developers. Written in TypeScript. Powered by 0x.
Stars: ✭ 200 (+284.62%)
Mutual labels:  erc721
awesome-cryptocollectibles
A collection about Awesome Crypto Collectibles (& Assets) - Yes, Non Fungible Tokens (NFTs) - Yes, Unique Bits & Bytes on the Blockchain - Buy! Sell! Hodl!
Stars: ✭ 37 (-28.85%)
Mutual labels:  erc721
lootloose.com
LootLoose lets you unbundle your Loot Bags into individual item NFTs or rebundle items into their original Loot Bags.
Stars: ✭ 33 (-36.54%)
Mutual labels:  erc721

ERC721 With On-Mint Generation

An example of an ERC721 token with efficient on-mint generation from 7 traits (taken from BAYC; see details below).

Note that code written for this example has not been audited.

Gas Usage

>>> forge test --optimize-runs 0
compiling...
success.
Running 1 test for "ERC721WithOnMintGenerationTest.json":ERC721WithOnMintGenerationTest
[PASS] testMint() (gas: 66211)

Running 9 tests for ERC721WithOnMintGenerationTest
[PASS] testGenerateRandomMetadata(uint256) (μ: 9201, ~: 9198)
[PASS] testGenerateRandomNumber(uint256) (μ: 2295, ~: 2297)
[PASS] testTrait1Cpw(uint256) (μ: 1879, ~: 1860)
[PASS] testTrait2Cpw(uint256) (μ: 1972, ~: 1960)
[PASS] testTrait3Cpw(uint256) (μ: 2158, ~: 2174)
[PASS] testTrait4Cpw(uint256) (μ: 2118, ~: 2131)
[PASS] testTrait5Cpw(uint256) (μ: 2045, ~: 2052)
[PASS] testTrait6Cpw(uint256) (μ: 2145, ~: 2155)
[PASS] testTrait7Cpw(uint256) (μ: 1768, ~: 1771)

Note that minting will cost ~15,000 gas more if it is an address's first mint, and ~15,000 gas more 1 out of 7 times. In practice, it should cost around 80,000 ~ 110,000 gas to mint a token with on-mint generation. See {ERC721WithOnMintGeneration-mint} for more information.

Traits

The trait probabilities were taken from BAYC. Properties 3, 4, 6 had more than 31 traits, so some were ommitted. Additionally, the probabilities were normalized to sum to less than or equal to 255. See {OnMintGeneration-selectRandomTrait} for more information.

Constraints

selectRandomTrait has 2 major constraints because _cpw is limited to data bitpacked into 1 uint256 to keep gas costs low:

  1. For a given a property, its traits must sum to less than or equal to 255.
  2. A property must have at most 31 traits.

Fortunately, most generative projects to date (Jan. 2022) fit the constraints mentioned above. If more is desired, work-arounds are possible by splitting up a property's cumulative probability weightings into more than just 1 uint256. See {OnMintGeneration-selectRandomTrait} for an explanation.

Using the algorithm

Read through ERC721WithOnMintGeneration.sol and OnMintGeneration.sol to understand how the algorithm is implemented first. Then, consider utilizing py_utils to help:

>>> python3 py_utils/generate_cpws.py
['0xffdebd9d7e60402007', '0xfdf5ebe9d9d8d1c5b8b4a7938e8a68584e2b1f12', '0xfdf4e8e0dbd4d0ccc9c6c4c2bbb2aeaba19793897f77726b5b58524c4a463e1e', '0xfffaf5ebe6dedad2cfc3bbb6afaaa8a399918d877f787569686158534b45431e', '0xfff7f1e3dac7c1b3aaa8a29e948c897f736135341e170c16', '0xfff8f4ebe5dfd8d0cdcbc9b6a8a2a19e9d9b9a8e8b89605f5b59575643403d1e', '0xffead4c9bdb7b306']

Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].