This is a sample ERC-1155 contract for the purposes of demonstrating integration with the OpenSea marketplace for crypto collectibles. We also include:
On top of the features from the OpenSea ERC721 sample contracts, ERC1155
Open MyLootbox.sol
Class
to reflect your rarity levels.NUM_CLASSES
to reflect how many classes you have (this gets used for sizing fixed-length arrays in Solidity)constructor
, set the OptionSettings
for each of your classes. To do this, as in the example, call setOptionSettings
with
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!
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.
Run
yarn
export INFURA_KEY="<infura_key>"
export MNEMONIC="<metmask_mnemonic>"
truffle migrate --network rinkeby
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! 🥳
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.
Install truffle locally: yarn add truffle
. Then run yarn truffle migrate ...
.
You can also debug just the compile step by running yarn truffle compile
.
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.
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.
These contracts are available to the public under an MIT License.
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.