Smart Contracts for creating NFTs on Opensea

Author picture

So you want to have your 10K NFT collection released right? Well buckle up, coz it ain’t that simple.

Since the majority of the Cryptocurrencies are going down (nowadays), so are sales of most of the bigger NFT collections as well. Maybe it is a good time to buy, since Ethereum is as cheap as it was in early 2021. Although Bill Gates mocked the Bored Apes for not driving the world forward, we believe that smart contracts and tokenized systems can be utilized in the future. If you are interested in trying out this wild ride, here is what you need to know. 


The process can be broken up into two major parts. Step number one, you’ll need to have those NFTs ready and then put them out on opensea.io.  

1. NFT creation process 

  a. Creating content 

  b. Creating data structure 

2. Smart contract and deployment 

1. NFT creation process – Generating the NFTs as “art” 

Lets talk about making NFTs as digital art. In this article we will focus on making a large collection instead of just one image. If you want to go with a singular image as an NFT, Opensea provides all the things you need. So for a handful of NFTs it makes more sense to utilize a marketplace’s UI. In that case you will not have your own smart contract and your metadata will not be on decentralized storage and of course for 10k NFTs it takes an awful lot of time. It is much more complex (and we think interesting as well) to go the full way and that is what we will explore in this post.

In the generation process you’ll need two things: a. Creating the content (images, gifs, videos or sounds) and b. you’ll need to have a data structure, a json file. This json file contains your metadata (which you’ll need for the minting). There are many services, YouTube videos, GitHub accounts where you can find tools for NFT creation. There are Node.js code lines zipped for generating the NFTs based on your designs, layers and also generating the JSON data structure. Or you can choose web services such as: https://www.nftport.xyz/, where the entire process can be done including the smart contract deployment and the minting. 

What we did was a generative art based collection of 10K NFTs. So first of all we came up with a topic, which was Rock n Roll, since we love heavy music. The name of the collection is Backstage Panther Cruue, make sure to check them Panther out here: (https://opensea.io/collec tion/backstage-panther-cruue-1). So we wanted to portrait certain types of characters, who you could find at a rock show or at the backstage of a small metal club or venue. After that we came up with the character type and it was a cartoon styled panther (since we love Pantera). When you are done with that, it’s time to be patient so the designer can finish all the properties. Each property is a layer in Photoshop, which you need to export and input into the Node.js code, so the generation can be finished. The code spills out the 10K images and also it makes the json data structure which will be important in making the smart contract. 

This contains the metadata, such as:

  • Image url: “This is the URL to the image of the item.” 
  • External url: “This is the URL that will appear below the asset’s image on OpenSea and will allow users to leave OpenSea and view the item on your site.” 
  • Description: “A human readable description of the item. Markdown is supported.” Name: “Name of the item.” 
  • Attributes: “These are the attributes for the item, which will show up on the OpenSea page for the item. (see below)” 
  • background_color: “Background color of the item on OpenSea. Must be a six-character hexadecimal without a pre-pended #.” 
  • Animation_url: “A URL to a multi-media attachment for the item. The file extensions GLTF, GLB, WEBM, MP4, M4V, OGV, and OGG are supported, along with the audio-only extensions MP3, WAV, and OGA.” 
  • Youtube_url: “A URL to a YouTube video.” 
  • Sometimes it also contains 
  • Blockchain: Ethereum or Polygon. 
  • Price: cost of one NFT is ETH. 
  • Collection: Name of your collection. 
  • Supply: How many of one particular NFT are available? 

Your metadata should be stored on a decentralized storage such as: IPFS (https://ipfs.io/). This is where your images are stored and the json files as well. The smart contract will get access to your content and metadata from these json files. 

Once you are done with your content creation (1/a) and you have your data structure (1/b) you are ready for step number two. 

2. Smart contract and deployment 

These are the frameworks of your agreement between buyer and seller, in code form, which is being deployed into a decentralized blockchain network. What does this mean? Well, its like a normal contract only written as software code and stored on the Ethereum network, so it will never parish (as long as the chain is alive). This means it is safe, it is (usually) publicly accessible and it  will never get lost and the owner can utilize its features. 

The contract comes with features and there are some which are self-executing. But before you can use it, it needs to be deployed into the blockchain so it can function. In order to do that you need to construct your code, add your IDs and of course pay gas fee for the deployment which is more expensive on Ethereum and is a lot cheaper on Polygon. Ethereum is the most well known and well documented decentralized and open-source blockchain with smart contract functionality. Ether (ETH or Ξ) is the native cryptocurrency of the platform. (https://en.wikipedia.org/wiki/Eth ereum). It’s gas fees are high because it is one of the most-used blockchain networks in the world but it is still preferred due to its positive traits providing security and preventing hijacks. A comparative analysis shows that it is the most decentralized smart contract blockchain currently.

The alternative approach, if you don’t want to spend that much on gas fees, is Polygon (also known as Matic Network). Its a protocol and framework for building and connecting Ethereum-compatible blockchain networks (https://golden.com/wiki/Polygon-ZXZJWEZ). While the Ethereum platform is more about the features and security, Solana (another alternative to Ethereum) and Polygon are more about affordable rates, faster speeds, and scalability. Polygon allows 65K of transactions per second, which makes it more affordable. Its Token is MATIC and that is what you need in order to deploy anything. Check out this comparison, which explains the differences between the chains. 

Comparison between Chains

Smart contracts permit trusted transactions between wallet IDs. We recommend Metamask (https://metamask.io/) for deployment and for just buying you can go with Coinbase (https://www.coinbase.com/). There is a growing amount of services for NFT creation, but be aware, there is a significant amount that will not cover everything you need. For example maybe the smart contract is not under your wallet ID, which means that you’ll not be in full control. 

For smart contracts it is essential to have your terms and functions (for example): 

  • Minting 
  • Token volume 
  • Burn 
  • Pause 
  • Vote 
  • Supply tracking 
  • Set aside NFTs 

This you can find here (https://docs.openzeppelin.com/contracts/4.x/wizard). The other important factor is, that the contract should be yours, meaning your wallet ID should be the one creating it. There are some services where you are not the owner, that sucks. Also Opensea.io has its ERC-1155 smart contract: if there is a singular user, who just wants to have an NFT uploaded, there is an easy way to do that manually via the OpenSea UI. 

Check it here: 0x2953399124F0cBB46d2CbACD8A89cF0599974963 OPENSTORE Token. 

Paste it here: https://polygonscan.com/ so you can see it for yourself (this is the opeansea collections: https://polygo nscan.com/address/0x2953399124F0cBB46d2CbACD8A89cF0599974963). 

It is better to have full control over your contract. Thats why we chose to do the whole process ourselves and we chose to go with ERC 721. So, let’s talk about token standards.

Token types 

There are several types of token standards you can use while developing and deploying smart contracts. A token standard is a programming framework how a token will function on Ethereum (or on Polygon). ERC 721 and ERC-1155 are the most common ones, they are the main building blocks of  token economics in Web3. “ERC” stands for Ethereum Request for Comments. ERC-721 is mostly known for that each token is unique (non fungible). When an ERC-721 token is created, there is one and only one of those tokens in existence (https://decrypt.c o/resources/erc-721-ethereum-nft-token-standard). So they are unique assets thats why they can hold their value, if they have value (meaning if there are buyers, who are willing to pay for them). The other commonly used token standard is ERC-1155, which was important for blockchain games, since it’s “fungibility-agnostic”, meaning it also takes care of fungible and and non-fungible. Its good for in-game coins and assets. Let’s say there is a medieval RPG and you can get access to a special loot, a type of sword, ERC-1155 covers it. 

“ERC-1155 is really like a vending machine for NFTs and fungible tokens, with advanced usability features and functionality like batch transfers to enable efficient, large-scale blockchain games and apps.” – Witek Radomski, co-creator of ERC-1155 

Developer environment 

Lets start with language, smart contracts are written is Solidity: “Solidity is an object-oriented, high-level language for implementing smart contracts. Smart contracts are programs which govern the behaviour of accounts within the Ethereum state.” (https://docs.soliditylang.org/en/v0.8.11/). A smart contract can be created in https://remix.ethereum.org/ or simply you can run it in your own developer environment (Visual Studio Code). Simply construct your smart contract based on the Opensea tutorial (https://docs.opensea.io/ docs/creating-an-nft-contract). 

If you want take a look at the Bored Ape Yacht Club’s smart contract, here it is:

https://etherscan.io/address/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d#code . Its also a good baseline, if you want to go on Ethereum.

For example there is this interesting line: 1936 – Here you’ll see this function: “Set some Bored Apes aside”. 

* Set some Bored Apes aside 


function reserveApes() public onlyOwner {  

 uint supply = totalSupply(); 

 uint i; 

 for (i = 0; i < 30; i++) { 

 _safeMint(msg.sender, supply + i); 


Now what they did is that they’ve set some apes aside for themselves. I believe this is what most NFT creators do, since they now which ones are the extra rare ones. 

These are the basics of what we ended up using 

pragma solidity ^0.8.0; 

import “@openzeppelin/contracts/token/ERC721/ERC721.sol”; 

import “@openzeppelin/contracts/access/Ownable.sol”; 

import “@openzeppelin/contracts/utils/Counters.sol”; 

import “@openzeppelin/contracts/utils/Strings.sol”; 

import “@openzeppelin/contracts/utils/math/SafeMath.sol”; 

import “./common/meta-transactions/ContentMixin.sol”; 

import “./common/meta-transactions/NativeMetaTransaction.sol”;

Once you have your smart contract ready, it’s time for deployment. We made that vie Remix. First you’ll need to compile it. Set the compiler then select injected web3 and hit deploy. If its on the blockchain you can check it on either etherscan or polygonscan. 

Once your smart contract is out there its time for minting, which is a feature in your smart contract. For that, use mint.js, which will mint the NFTs under your wallet ID. This means your wallet ID is the creator of your NFTs and they are in opensea and are listed in your collection. It can go automatically, so set your number to 10,000 and the minting will take a while, but it will be ready. The result should be something like this:

Once they are in your collection on opensea you can edit your collection: 

  • Name 
  • Logo image 
  • Featured image 
  • Banner image 
  • URL 
  • Description 
  • Category 
  • Links: social links 
  • Royalties: this is important what amount you’ll receive after a resale. 
  • Blockchain: its already covered 
  • Display theme: how item listings are shown 
  • Explicit or sensitive content 
  • Payment tokens: how you want to get paid, 
  • Collaborators 

Now you have your pimped up opensea collection, and these NFTs are ready, so you are ready for accepting offers but they are not yet listed under a price. If you go with Polygon there is no API for bulk changes (YET). On Ethereum you can change all NFTs, listed as available on a certain price (this means under Buy Now they are listed) via opensea API. You’ll need to request an API key here: https://docs.opensea.io/reference/request-a n-api-key. So you can set all 10K NFTs to Buy Now on for example: 0.01 ETH. On Polygon, not yet. What you can do is to set them manually: 



Sign via Metamask 

This is the entire process. If there are questions or you want to have your or your brands NFTs out there let us know.

Related articles

fintech secrets