Your very own Smart Contract for NFTs

Amir Soleymani
6 min readSep 6, 2021

--

One of the aspects of being an artist in NFT space is to have your own provenance on the blockchain and nothing proves this more than having your own smart contract.

By having your own smart contract, you will be able to mint your works under one collection & under your own name.

Of course this is only good if you plan to sell your items on an open market like Opensea and you will not be able to sell works from your own smart contract on any other platform.

Having your own smart contract & minting your work is not an easy process and you must have a basic knowledge of technology and associated terms in blockchain space.

This process consists of:

1- Writing a smart contract that you could mint intangible tokens (unique works) on the blockchain,

2- Have that smart contract deployed on the blockchain,

3- Verifying the source code on etherscan

4- Creating metadata files & uploading them to the IPFS along with the actual artwork that can be an image, video or even a Javascript/HTML code.

5- Minting the work on the blockchain by connecting the token, the metadata and the artwork and binding them together on the blockchain.

I have written a simple smart contract that allows you to mint unlimited unique works each with its own metadata (tokenURI). You can also burn tokens that you still have control over along with all other standard functions of a smart contract.

You can see the contract source code here:

In this source code, you need to change 3 parts to customize it:

Line 1351 #YOURCONTRACTNAME#

Whatever your contract/collection is. eg. MondoirPhotographyCollection. Note that this can not have any spaces.

Line 1362 #YOUR CONTRACT NAME# & #SYMBOL#

Same name but here you can use spaces. eg. Mondoir Photography Collection. And the symbol is the token name. It might be a bit confusing but its basically something like ETH & BTC. So feel free to use some parts of your collection name. eg. MPC (for Mondor Photography Collection)

and that’s about it in customizing your contract.

You now need to head over to Remix to deploy your contract. Remix IDE is an open source web and desktop application. It fosters a fast development cycle and has a rich set of plugins with intuitive GUIs. Remix is used for the entire journey of contract development as well as being a playground for learning and teaching Ethereum.

Refrence A1
Reference A1

On Remix webpage and on the left hand side, there is a file browser.

Click on the Single Sheet (number 1) to create a new file. Name this file your smart contract name ending with sol. So your file name is should be something like this: myContract.sol

Then copy the contents of the contract source code on my github page and paste it in the file you’ve just created.

You can update those 3 items I’ve mentioned earlier here. (line 1358 & 1370) and dont forget to remove the # signs.

Next stop, go to item number 2 (Reference A1 picture) to compile your contract. Make sure your screen & options look like mine here and press compile.

If you had Auto Compile selected, it probably already compiled your contract but there's no harm of compiling it again.

Once done, go to menu number 3 to deploy the contract on ethereum network.

Now, depending on your need, you may want to deploy this to testnet to test your contract which in this case you can use the VM machines in this list.

If you want to use your metamask and deploy either on mainnet or testnets, use Web3 Provider and connect your metamask.

Make sure the correct contract is selected on the CONTRACT section and press deploy.

upon successful deployment, you should see the contract name & address below the deploy button.

Copy the contract address by clicking on the 2 stacked papers in front of contract name & address and headover to etherscan to verify your contract.

Depending on your network, you can go to https://etherscan.io/ if you’ve chosen to deploy on mainnet and https://rinkeby.etherscan.io/ or https://ropsten.etherscan.io/ if on testnet.

On Etherscan, paste your contract address on the search bar and go to your newly created contract.

Head over to Contract tab and click on Verify and Publish link.

Select the compiler type, version and license type according to Remix.

Head back to Remix & copy the contract source code.

Paste the contract source code & answer Yes to Optimization option.

IMPORTANT HINT:

You might get error message at this stage. I had this issue on Chrome browser so I tried with Safari and it worked fine.

After hitting Verify & Publish, etherscan should read your contract source code & figure out the ABI for this contract & verify it.

After your contract is verified, you will be able to interact with it on the contract tab with newly added buttons of Read & Write. In the write section, you will be able to mint new works.

Now the next part is to actually mint the work.

To mint, you need to create metadata json file and upload it along with the image/video/html file to the IPFS. Ive explain a bit on this topic here before:

Once your files are on the IPFS, grab the linkt o your metadata.json file and head over to ethersan and to your contract page.

On there, go to write and then mint.

Here you can choose to which address you want to send this newly minted work. Obviously this would be your own address. Then you can chose a token ID for this work. This is a number & completely up to you to come up with a number as long as its not used before in your smart contract. Its a good practice to come up with a system of numbering for your works.

For example still images start with 0001 and then add the next work to the index. eg. 000101

Then on the tokenURI, paste the link to the metadata.json file for your work and press mint. Make sure your metamask is connected & that you have enough eth to cover the gas fee. Once done, the newly minted work will be available on your opensea account and you're free to choose how you want to sell it.

This smart contract allows you to mint unlimited number of unique works each with their own token ID & tokenURI.

Hope this article could help you become more independent in this space.

If you had any question, Ill do my best to answer on my twitter https://twitter.com/mondoir

Peace ✌️

--

--