• This repository has been archived on 09/Sep/2022
  • Stars
    star
    605
  • Rank 74,072 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 5 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Example semi-fungible collectible, to demonstrate OpenSea integration for an ERC-1155 contract

OpenSea ERC-1155 Starter Contracts

About these contracts

This is a sample ERC-1155 contract for the purposes of demonstrating integration with the OpenSea marketplace for crypto collectibles. We also include:

  • A script for minting items.
  • A factory contract for making sell orders for unminted items (allowing for gas-free and mint-free presales).
  • A configurable lootbox contract for selling randomized collections of ERC-1155 items.

On top of the features from the OpenSea ERC721 sample contracts, ERC1155

  • supports multiple creators per contract, where only the creator is able to mint more copies
  • supports pre-minted items for the lootbox to choose from

Configuring the Lootbox

Open MyLootbox.sol

  1. Change Class to reflect your rarity levels.
  2. Change NUM_CLASSES to reflect how many classes you have (this gets used for sizing fixed-length arrays in Solidity)
  3. In constructor, set the OptionSettings for each of your classes. To do this, as in the example, call setOptionSettings with
    1. Your option id,
    2. The number of items to issue when the box is opened,
    3. An array of probabilities (basis points, so integers out of 10,000) of receiving each class. Should add up to 10k and be descending in value.
  4. Then follow the instructions below to deploy it! Purchases will auto-open the box. If you'd like to make lootboxes tradable by users (without a purchase auto-opening it), contact us at [email protected].

Why are some standard methods overridden?

This contract overrides the isApprovedForAll method in order to whitelist the proxy accounts of OpenSea users. This means that they are automatically able to trade your ERC-1155 items on OpenSea (without having to pay gas for an additional approval). On OpenSea, each user has a "proxy" account that they control, and is ultimately called by the exchange contracts to trade their items.

Note that this addition does not mean that OpenSea itself has access to the items, simply that the users can list them more easily if they wish to do so!

Requirements

Node version

Either make sure you're running a version of node compliant with the engines requirement in package.json, or install Node Version Manager nvm and run nvm use to use the correct version of node.

Installation

Run

yarn

Deploying

Deploying to the Rinkeby network.

  1. You'll need to sign up for Infura. and get an API key.
  2. You'll need Rinkeby ether to pay for the gas to deploy your contract. Visit https://faucet.rinkeby.io/ to get some.
  3. Using your API key and the mnemonic for your MetaMask wallet (make sure you're using a MetaMask seed phrase that you're comfortable using for testing purposes), run:
export INFURA_KEY="<infura_key>"
export MNEMONIC="<metmask_mnemonic>"
truffle migrate --network rinkeby

Deploying to the mainnet Ethereum network.

Make sure your wallet has at least a few dollars worth of ETH in it. Then run:

yarn truffle migrate --network live

Look for your newly deployed contract address in the logs! 🥳

Viewing your items on OpenSea

OpenSea will automatically pick up transfers on your contract. You can visit an asset by going to https://opensea.io/assets/CONTRACT_ADDRESS/TOKEN_ID.

To load all your metadata on your items at once, visit https://opensea.io/get-listed and enter your address to load the metadata into OpenSea! You can even do this for the Rinkeby test network if you deployed there, by going to https://rinkeby.opensea.io/get-listed.

Troubleshooting

It doesn't compile!

Install truffle locally: yarn add truffle. Then run yarn truffle migrate ....

You can also debug just the compile step by running yarn truffle compile.

It doesn't deploy anything!

This is often due to the truffle-hdwallet provider not being able to connect. Go to infura.io and create a new Infura project. Use your "project ID" as your new INFURA_KEY and make sure you export that command-line variable above.

Minting tokens.

After deploying to the Rinkeby network, there will be a contract on Rinkeby that will be viewable on Rinkeby Etherscan. For example, here is a recently deployed contract. You should set this contract address and the address of your Metamask account as environment variables when running the minting script:

export OWNER_ADDRESS="<my_address>"
export FACTORY_CONTRACT_ADDRESS="<deployed_contract_address>"
export NETWORK="rinkeby"
node scripts/advanced/mint.js

Note: When running the minting script on mainnet, your environment variable needs to be set to mainnet not live. The environment variable affects the Infura URL in the minting script, not truffle. When you deploy, you're using truffle and you need to give truffle an argument that corresponds to the naming in truffle.js (--network live). But when you mint, you're relying on the environment variable you set to build the URL (https://github.com/ProjectOpenSea/opensea-creatures/blob/master/scripts/mint.js#L54), so you need to use the term that makes Infura happy (mainnet). Truffle and Infura use the same terminology for Rinkeby, but different terminology for mainnet. If you start your minting script, but nothing happens, double check your environment variables.

License

These contracts are available to the public under an MIT License.

ERC1155 Implementation

To implement the ERC1155 standard, these contracts use the Multi Token Standard by Horizon Games, available on npm and github and also under the MIT License.

More Repositories

1

opensea-js

TypeScript SDK for the OpenSea marketplace
TypeScript
2,278
star
2

seaport

Seaport is a marketplace protocol for safely and efficiently buying and selling NFTs.
Solidity
2,141
star
3

opensea-creatures

Example non-fungible collectible, to demonstrate OpenSea integration
JavaScript
1,167
star
4

embeddable-nfts

Easily embed OpenSea listings in your website!
TypeScript
329
star
5

operator-filter-registry

Solidity
311
star
6

seadrop

Smart contracts for primary drops on EVM chains
Solidity
290
star
7

seaport-js

A TypeScript library to interface with the Seaport marketplace.
TypeScript
255
star
8

opensea-whitelabel

Easily whitelabel an OpenSea marketplace for your own website
TypeScript
226
star
9

metadata-api-nodejs

Sample metadata API for crypto collectibles, written in Node.js
JavaScript
193
star
10

stream-js

A TypeScript SDK to receive pushed updates from OpenSea over websocket.
TypeScript
166
star
11

seaport-gossip

A peer-to-peer network for sharing Seaport orders.
TypeScript
125
star
12

metadata-api-python

Simple API for serving ERC721 metadata
Python
117
star
13

nft-tutorial

A very basic NFT tutorial repository for absolute beginners in the world of Web3 and smart contracts
JavaScript
96
star
14

marketplace-benchmarks

A comparison supported features and respective gas overhead for NFT marketplaces
Solidity
70
star
15

meta-transactions

Solidity
49
star
16

seaport-order-validator

Seaport Order Validator provides a simple method for validating and diagnosing Seaport orders
Solidity
48
star
17

shipyard-core

Solidity
48
star
18

seaport-core

Core Seaport smart contracts
Solidity
45
star
19

SIPs

The Seaport Improvement Proposal repository
31
star
20

ethmoji-contracts

Ethmoji smart contracts
JavaScript
22
star
21

seaport.py

Python
21
star
22

seaport-sol

Solidity helpers for working with Seaport on and off-chain using Forge scripts
Solidity
21
star
23

ships-log

An example dapp listing recent auctions and bids on OpenSea, with the ability to buy items or accept offers right from the page.
JavaScript
20
star
24

seaport-1.6

A unified repo containing the core Seaport contracts, types, tools, and tests to facilitate Seaport 1.6 development
Solidity
20
star
25

ethmoji-js

SDK for Ethmoji blockchain avatars
JavaScript
19
star
26

opensea-stream-discord-webhook

A sample repo showing how a developer using the OpenSea Stream API might be able to connect a Discord webhook to send messages whenever new events occur for a collection
TypeScript
18
star
27

0x-fee-wrapper

Solidity
16
star
28

shipyard

Template Repo for OpenSea smart contract development
Solidity
13
star
29

redeemables

EVM smart contracts for redeemables and dynamic traits
Solidity
12
star
30

seaport-types

Standalone structs and interfaces related to Seaport
Solidity
12
star
31

tstorish

Use TSTORE in contracts deployed to multiple chains with varying opcode support
Solidity
11
star
32

ethdenver-workshop

Devcon 5 workshop
JavaScript
10
star
33

seaport-generic-adapter

A proof of concept Seaport app that enables fulfilling non-Seaport listings through Seaport.
Solidity
10
star
34

seaport-deploy

A utility for deploying Seaport to local chains for use in testing.
Solidity
9
star
35

seaport-hooks

A collection of various Seaport Hooks (zone hooks, contract hooks, and item hooks): https://docs.opensea.io/docs/seaport-hooks
5
star
36

ethmoji-js-demo

JavaScript
5
star
37

jellyfish

Build UIs as state machines using Compose.
Kotlin
5
star
38

buy-sell-opensea-sdk-demo

https://docs.opensea.io/docs/buy-sell-nfts
TypeScript
3
star
39

vercel-repros

TypeScript
1
star