Minting NFTs on the SIMBA Enterprise Platform

MINTING NON-FUNGIBLE TOKENS (NFTs)

This walk-through demonstrates how easy it is to mint and interact with an ERC721 Non-Fungible Token (NFT) on the SIMBA Enterprise Platform. Open Zeppelin Solidity libraries were used as a starting point to build our example NFT smart contract. The following piece of media will be used as our NFT:

ERC721 EXAMPLE CONTRACT – DEPLOYING THE CONTRACT AND MINTING A SIMBA NFT:
Example Solidity smart contract code:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;
import “@openzeppelin/4.0.0/contracts/token/ERC721/ERC721.sol”;
import “@openzeppelin/4.0.0/contracts/utils/Counters.sol”;
import “@openzeppelin/4.0.0/contracts/token/ERC721/extensions/ERC721URIStorage.sol”;
contract SimbaNFTExample is ERC721URIStorage {

using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721(“SimbaNFTExample”, “SIMBA”) {}
function mint(address to, string memory tokenURI) public returns (uint256) {

_tokenIds.increment();
uint256 tokenId = _tokenIds.current(); _mint(to, tokenId);
_setTokenURI(tokenId, tokenURI);

return tokenId; }

}

All NFTs minted by an NFT contract need a unique tokenId. The tokenIds for the NFTs minted by our example smart contract (SimbaNFTExample) will use one up numbers starting with 1. The ERC721URIStorage extension is used to allow for adding a tokenURI to the NFT. This is typically a URL used to reference a JSON metadata file containing information about the NFT. This JSON metadata file will contain a reference to the location of the NFT media file (the artwork, video, song, etc.).

 

 

To get started using the SIMBA Enterprise Platform we first take the SimbaNFTExample smart contract and load it into expert mode of the Smart Contract Designer. We then check that it compiles and save the contract as SimbaNFTExample. Next we add it to an application called SimbaNFTExample and deploy the contract to a Quorum blockchain network:

 

 

Note: This Solidity mart contract can also be deployed through the SIMBA Enterprise Platform to public networks such as Ethereum and Avalanche.
After deployment, the generated REST API can now be used to interact with the SimbaNFTExample contract functionality

 

 

To mint an NFT using the smart contract we just deployed we would first call the mint function. This function takes two arguments, the to address and the tokenURI. The to address will be the owner of the NFT once minted. The tokenURI is a URL that will point to a JSON file that contains the NFT metadata. This file describes the NFT itself, and most importantly contains the location of the actual NTF media. Before we can call the mint function, we first need to have our NFT media and metadata files available.
For this example we first uploaded our media content for the NFT to:
https://simbachain.com/images/SIMBA-Retro-Gamer.png

 

 

SIMBA Chain’s approach to minting NFTs involves incorporating the metadata and content based identifiers into the NFT on chain. However, for simplicity for this demo we will be storing our NFT related media content on the SIMBA Chain website. Consequently, the next step is to take the URL for the media and populate a JSON metadata file for the NFT we are about to mint. In this JSON we also set the id field to 1 as this will be the tokenId generated by the contract for the first token we mint, and then populate the name and description fields for the NFT.

 

{“id”:”1”
“name”:”Retro Gamer”,
“description”:”SIMBA Retro Gamer NFT”,
“image”:”https://simbachain.com/images/SIMBA-Retro-Gamer.png”
}

 

Again, for simplicity we will be storing our NFT metadata file on the SIMBA Chain website for this example, but storage in a decentralized platform such as IPFS is recommended. Our metadata file can be found at https://simbachain.com/images/SIMBA-Retro-Gamer_metadata.json.

 

 

We can now mint the NFT by calling the mint function by providing the address we would like to own the token as the to argument, and the URL for our metadata file as the tokenURI argument. The request body arguments should look like the following:

 

{
“to”: “0x303c9478D744e00D7EC1d6c62976204FbAb76786”,
“tokenURI”: “https://simbachain.com/images/SIMBA-Retro-Gamer_metadata.json”
}

 

 

Executing the mint function from the REST API results in a transaction being submitted to the Quorum blockchain network to mint the NFT:

 

 

Reloading the application page we can now see that a second transaction completed. This transaction called the mint method with the request body we provided above.

 

 

At this point we have successfully minted our first NFT. If we click the tokenURI link it takes us to the metadata file we set up for our NFT before minting:

 

 

To verify that our NFT was minted on the blockchain we can now call the smart contract’s tokenURI function, with the tokenId set to 1:

 

 

This returns the metadata URL we used when minting the NFT: https://simbachain.com/images/SIMBA-Retro-Gamer_metadata.json

We can also call the ownerOf function with the tokenId set to 1 to verify that the address we provided during minting (0x303c9478D744e00D7EC1d6c62976204FbAb76786) is the owner of the NFT. We can see in the response data that owner address does match the address we provided at minting.

 

To transfer ownership of the NFT to a new owner with address 0xca843569e3427144cead5e4d5999a3d0ccf92b8e, we can call the transferFrom function. To call transferFrom, we set the from field to the current owner’s address (0x303c9478D744e00D7EC1d6c62976204FbAb76786), then set the to field to the new owner’s address (0xca843569e3427144cead5e4d5999a3d0ccf92b8e), and set the tokenId field to 1:

 

 

Back on the application page, we can see that this results in a third transaction being submitted to the blockchain for the transferFrom method with the inputs we provided in the previous step:

 

 

Trying to verify the owner of the NFT using the ownerOf function now gives us back the address of the new owner (0xca843569e3427144cead5e4d5999a3d0ccf92b8e), indicating that the transfer of ownership was successful:

 

 

We have successfully deployed an NFT contract, minted an NFT, and transferred it’s ownership using the SIMBA Enterprise Platform.
This walk-through only highlights a small subset of the functionality provided by the ERC721 NFT  standard and its extensions. More information is available on the ERC721 standard at: https://eips.ethereum.org/EIPS/eip-721

 

FILES
The NFT media and metadata file used in this walk-through can be found at:

• https://simbachain.com/images/SIMBA-Retro-Gamer.png
• https://simbachain.com/images/SIMBA-Retro-Gamer_metadata.json