Deploy an NFT

We will build a BHRC721 contract based on the Openzeppelin contracts. Let's install Openzeppelin contracts for our project`

npm install @openzeppelin/contracts

We can import the BHRC721 contract from Openzeppelin by the following import statement.

import "openzeppelin-contracts/contracts/token/BHRC721/BHRC721.sol";

Pre-requisites

  1. Install Metamask

  2. Configure Bahamut Mainnet on Metamask

  3. Get mainnet token

Compile and Deploy BHRC-721 Token

Open Remix IDE then create a new MyNFT.sol contract and copy the below contract code to MyNFT.sol.

// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.13;

import "openzeppelin-contracts/contracts/token/BHRC721/BHRC721.sol";

import "openzeppelin-contracts/contracts/access/Ownable.sol";

contract MyNFT is ERC721, Ownable{

string private _URIBase;

constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_) {

_transferOwnership(msg.sender);

}

function mint(address to, uint256 tokenId) public onlyOwner {

_safeMint(to, tokenId);

}

function setBaseURI(string memory baseURI_) public onlyOwner {

_URIBase = baseURI_;

}

function _baseURI() internal view override returns (string memory) {

return _URIBase;

}

}

Deployment process is the same as mentioned in BHRC-20 token deployment. If everything goes well, we will see the address of the deployed contract and the transaction hash for the deployment. Then we can mint NFT.

Add Metadata

Our minted NFT has no metadata associated with it. Without metadata, an NFT token is nothing but a token with an ID. Our smart contract implements the BHRC721 meta extension, and it has the following method for getting the metadata URI of an NFT token:

function tokenURI(uint256 _tokenId) external view returns (string);

Prepare Metadata

The metadata of an NFT token is presented in a JSON file. Here is an example:

{

"description": "My NFT",

"image": "your image url",

"name": "your token name",

"attributes": [

{

"trait_type": "xxxx",

"value": "yyyy"

},

{

"trait_type": "xxxxx",

"value": yyyyy

}

]

}

  1. Name is the name of this item(i.e, this NFT token), because each NFT token may have a different name.

  2. Image is the link to the image of this NFT token.

  3. Description is a short description of this NFT token.

  4. Attributes is a list of attributes that this NFT token has.

Apart from the commonly used fields in the above example, some other fields are also supported in the metadata JSON file.

You should create one metadata JSON for each of your NFT tokens. Let's assume you are hosting all the metadata JSON files on the host of my-nft-metadata.com , and the metadata JSON of each NFT token should have the following format:

https://my-nft-metadata.com/idOfToken

If you upload all your metadata JSON files to IPFS, you should add the whole directory that includes all the JSON files. Then, all the JSON files can be visited with the same base URI.

After uploading all the metadata JSON files somewhere and hosting them with the same base URI, we can set the base URI of the contract.

This standard outlines a smart contract interface that can represent any number of fungible and non-fungible token types. Existing standards such as BHRC721 require deployment of separate contracts per token type. The BHRC721 standard's token ID is a single non-fungible index and the group of these non-fungibles is deployed as a single contract with settings for the entire collection. In contrast, the BHRC-1155 Multi Token Standard allows for each token ID to represent a new configurable token type, which may have its own metadata, supply and other attributes.

Compile and Deploy BHRC-1155 Token

Open Remix IDE then create a new GameItems.sol contract and copy the below contract code to GameItems.sol.

// contracts/GameItems.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

contract GameItems is ERC1155 {

uint256 public constant GOLD = 0;

uint256 public constant SILVER = 1;

uint256 public constant THORS_HAMMER = 2;

constructor() public ERC1155("https://game.example/api/item/{id}.json") {

_mint(msg.sender, GOLD, 10**18, "");

_mint(msg.sender, SILVER, 10**27, "");<

Last updated