Release PRC-721 Token

Before you start, you will need to prepare the following:

  1. Metamask Wallet

  2. Have at least 1 PSC

Adding files to IPFS

We need to host the artwork corresponding to NFT and create a metadata file; to do this, we will use IPFS- a distributed system for peer-to-peer file storage and sharing. Follow the installation instructions in the IPFS documentation to download and install the IPFS CLI based on your operating system.

The following are the steps for hosting image and metadata files:

Create the IPFS repo. Initialize the IPFS repo by typing the following in a terminal window

 $ ipfs init

Start the IPFS daemon. Open a separate terminal window and type the following:

$ ipfs daemon

To add an image to IPFS , go to the first terminal window and add the image to IPFS (here it is art.png).

$ ipfs add art.png

Copy the hash starting from Qm and add the https://ipfs.io/ipfs/prefix, it must look like this:https://ipfs.io/ipfs/QmdrswwrbcfPeknN2BRLVmyWbWRsKSC3vSNhV9Gkvhk1mL.

Add a JSON file to IPFS. Create a JSON file, nft.json, and save it in the same directory as the image. JSON file format:

{
    "name": "NFT Art",
    "description": "This image shows the true nature of NFT.",
    "image": "https://ipfs.io/ipfs/QmZzBdKF7sQX1Q49CQGmreuZHxt9sVB3hTc3TTXYcVZ7jC",
}

Now add the JSON file:

$ ipfs add nft.json

Copy the hash starting at Qm and add the https://ipfs.io/ipfs/prefix,it must look like this:https://ipfs.io/ipfs/QmWKqwMJQHSfpfRFGUVGPFFtkBJ5WkFzhjQpruhSLtLWXB, save this URL. We need this to mint NFT.

Create our own Token

For convenience and security, we will use the 0xcert/ethereum-erc721 contract to create our NFT contract.With 0xcert/ethereum-erc721, we do not need to write the entire ERC-721 interface. Instead, we can import the library contract and use its functions.Go to the Ether Remix IDE, make a new Solidity file, for example nft.sol, and paste the following code into the Solidity file.

// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
 
import "https://github.com/0xcert/ethereum-erc721/src/contracts/tokens/nf-token-metadata.sol";
import "https://github.com/0xcert/ethereum-erc721/src/contracts/ownership/ownable.sol";
 
contract newNFT is NFTokenMetadata, Ownable {
 
  constructor() {
    nftName = "Synth NFT";
    nftSymbol = "SYN";
  }
 
  function mint(address _to, uint256 _tokenId, string calldata _uri) external onlyOwner {
    super._mint(_to, _tokenId);
    super._setTokenUri(_tokenId, _uri);
  }
 
}

The following is an explanation of the code:

Line 1: Specifies the SPDX license type, which was added after Solidity ^0.6.8. These licenses can help resolve/avoid copyright issues whenever the source code of a smart contract is made available to the public. If you don't want to specify any license type, you can use a special value UNLICENSED, or just skip the whole comment (it won't cause an error, just a warning).

Line 2: Declares the Solidity version.

Lines 4-5: Import the 0xcert/ethereum-erc721 contract.

Line 7: The contract is named newNFT, which inherits the NFTokenMetadata and Ownable contracts.

Lines 9-12: Initialize the constructor and set the name and token symbol.

Line 14: Declare the function mint with three parameters, the variable _to for the address, which stores the address of the NFT token recipient; the variable _tokenId for uint256, which will hold the token id; and the variable _uri for the string, which will store the URI of the JSON file. Declare mint as an external function that can be accessed from outside of other smart contracts and the current contract.

Line 15: Use the recipient's address and token ID to mint the tokens.

Line 16: Set the token URI using the token id and the URI of the JSON file.

Compile the smart contract and deploy it using Injected Web3 (be sure to select Ropsten testnet on Metamask before compiling the contract). Approve the transactions coming to metamask.

If you receive an error message before deployment: This contract may be abstract, make sure the appropriate contract is selected under the Contracts tab. Confirm the transaction in Metamask.

Now go to the Deployed Contracts section in Remix and expand the deployed contracts. You will see a bunch of functions/methods. Expand the mint function and add the following parameters:

  1. Add your Ropsten address to _to.

  2. Enter any numeric value in _tokenid (1 is recommended, as it is the first).

  3. In the _uri field, add the URI of the JSON file obtained in the previous section.

Click on the transaction and confirm the transaction from metamask. (Requires that you already have ETH on the Ropsten chain)

You can see other details such as name, symbol, owner or tokenuri by entering the token id we mentioned before.

Congratulations on creating your own NFT, helping your artist friends post their artwork to the Ether Blockchain, or becoming an artist yourself.

Last updated