Harmony
Support ForumGithubTelegramDiscord
  • Welcome
  • 🎶General
    • Introduction
      • What is Harmony?‌
      • Roadmap
      • Strategy & Architecture
      • Study Materials
      • FAQ
    • Technology
      • Key Features
      • Randomness
      • Sharding
      • Consensus
      • Effective Proof-of-Stake
      • Tokenomics
      • Transactions
    • LayerZero Bridge
      • Important Notice
      • Bridge tutorial
      • FAQ
        • What token will I get after the bridge
        • How to find a bridged token address
    • Ecosystem
      • Wallets
        • 1Wallet
        • Gnosis Safe
        • Hardware Wallets
          • Trezor
          • Ledger Nano
            • Ledger with Metamask
            • Download & Setup
            • Ledger with HMY CLI
            • Ledger with Staking Dashboard
              • Sign In With Ledger
              • Sending transactions via Ledger
              • Staking Transactions via Ledger
          • Safepal
            • Download & setup
            • Create/import account
            • Send transaction
        • Browser Extension Wallets
          • Metamask
            • Installing MetaMask
            • Adding Harmony
            • Create a New Account
            • Sending & Receiving
            • Adding Custom Harmony Tokens
            • Import an Account
          • Math Wallet
            • Download & Setup
            • Create/Import/Export Wallet
            • Sending Transactions
            • Staking
            • Collecting Rewards
            • Undelegating
          • Harmony Chrome Extension Wallet
        • Desktop Wallets
          • Guarda Wallet
          • Staking4All Wallet
        • Mobile Wallets
          • Metamask Wallet
          • Blits Wallet
          • Cobo Wallet
          • Frontier Wallet
          • Guarda Wallet
          • Infinity Wallet
          • ONTO Wallet
          • Sef Wallet
          • Trust Wallet
          • Trustee Wallet
        • Web Wallets
          • Guarda Wallet
        • HMY CLI (Harmony Command Line Interface)
          • Download & Setup
          • Create or Import Wallet
          • Sending Transactions
          • Staking Transactions
          • Querying Balances
          • Querying the Blockchain
          • List of Transaction Error Messages
          • Cookbook
          • Other CLI References
      • DApps
        • User Guide
        • DeFi
          • Sushi
          • Onsen
        • CLI 1Wallet User Guide
        • Media
          • Timeless
        • FAQ
        • NFTs
      • Partners
        • Exchanges
        • Fiat Gateways
        • DeFi Protocols
      • Integrations
      • Cross-Border Finance
      • DAOs
        • Components & Tools
          • Snapshot
        • Community DAO
        • Validator DAO
        • Developer DAO
    • Community
  • 🏗️Developers
    • Getting Started
      • Network & Faucets
      • List of RPC Providers
      • Remix IDE
      • Dev Environment Setup
      • Ethereum Compatibility
    • Deploying on Harmony
      • Using Remix
        • Ethereum Remix
        • Harmony Remix
      • Using Truffle
      • Using Hardhat
      • Using Web3
      • Using Harmony-JS
        • Setup
        • Compile & Deploy
        • Demo: Deploying an Ethereum Smart Contract on Harmony
      • Deploy HRC20
      • Smart Contract Verification
    • SDK
      • Web3.js
        • Using Web3.js to Send Transactions on Harmony
        • Find the last transaction
      • JavaScript SDK
      • Go CLI
      • Java SDK
      • Python SDK
      • Harmony Ethers.js Wrapper
    • API
      • Methods
        • Account Methods
          • hmy_getBalanceByBlockNumber
          • hmy_getTransactionCount
          • hmy_getBalance
        • Filter Methods
          • hmy_getFilterLogs
          • hmy_newFilter
          • hmy_newPendingTransactionFilter
          • hmy_newBlockFilter
          • hmy_getFilterChanges
          • hmy_getLogs
        • Transaction Related Methods
          • hmy_getStakingTransactionByBlockHashAndIndex
          • hmy_getStakingTransactionByBlockNumberAndIndex
          • hmy_getStakingTransactionByHash
          • hmy_getCurrentTransactionErrorSink
          • hmy_getPendingCrossLinks
          • hmy_getPendingCXReceipts
          • hmy_getCXReceiptByHash
          • hmy_pendingTransactions
          • hmy_sendRawStakingTransaction
          • hmy_getTransactionsHistory
          • hmy_sendRawTransaction
          • hmy_getTransactionReceipt
          • hmy_getBlockTransactionCountByHash
          • hmy_getBlockTransactionCountByNumber
          • hmy_getTransactionByHash
          • hmy_getTransactionByBlockNumberAndIndex
          • hmy_getTransactionByBlockHashAndIndex
          • hmy_getBlockByNumber
          • hmy_getBlockByHash
          • hmy_getBlocks
        • Contract Related Methods
          • hmy_estimateGas
          • hmy_getStorageAt
          • hmy_call
          • hmy_getCode
        • Protocol Related Methods
          • hmy_isLastBlock
          • hmy_epochLastBlock
          • hmy_latestHeader
          • hmy_getShardingStructure
          • hmy_blockNumber
          • hmy_syncing
          • hmy_gasPrice
          • net_peerCount
          • hmy_getEpoch
          • hmy_getLeader
        • Staking Related Methods
          • hmy_getCirculatingSupply
          • hmy_getTotalSupply
          • hmy_getStakingNetworkInfo
          • hmy_getAllValidatorInformation
          • hmy_getAllValidatorInformationByBlockNumber
          • hmy_getCurrentUtilityMetrics
          • hmy_getDelegationsByValidator
          • hmy_getDelegationsByDelegatorAndValidator
          • hmy_getDelegationsByDelegator
          • hmy_getValidatorMetrics
          • hmy_getMedianRawStakeSnapshot
          • hmy_getElectedValidatorAddresses
          • hmy_getAllValidatorAddresses
          • hmy_getCurrentStakingErrorSink
          • hmy_getValidatorInformation
          • hmy_getValidators
          • hmy_getSignedBlocks
          • hmy_isBlockSigner
          • hmy_getBlockSigners
        • Tracing Methods
          • trace_block
          • trace_transaction
      • Sample Code
    • Tools
      • Harmony VRF
      • The Graph
      • Envio
      • Ganache
        • Harmony Ganache
      • Harmony-React
      • Oracles
        • Band Protocol
      • Smart Contract Verification
    • Tutorials
      • Deploying HRC20
      • Deploying HRC721/NFT
      • The Graph - Subgraphs
        • Building & Deploying Subgraph (local node)
      • Using Band Oracle
      • Using Crosschain API
        • Scripts
        • Testing
        • Webserver
      • Using Web3.py & Pyhmy
      • Using IPFS & Filecoin
        • Using IPFS
        • Using NFT.storage
      • Indexing HRC20 with Envio
      • Building a Simple Metaverse Contract
      • Building a Simple Bridge with Ethereum
      • Staking for Multisig
    • DApp Examples
      • DApp Samples
      • Games
        • Harmony Puzzle
      • Cross-Chain
      • DeFi
      • Hackathons
        • DevPost
        • Hack the Horizon
      • Others
    • Wallets
      • Metamask
        • Interacting With Metamask
        • Using Metamask with Harmony Smart Contracts
        • Add or Switch to Harmony chain on Metamask
      • Harmony Chrome Extension Wallet
      • Math Wallet
      • WalletConnect
    • Harmony Stack and Projects
  • 🌏Network
    • Governance
      • Network Governance
        • Voting via Governance App
        • Voting via HMY CLI
      • HRC-20 Governance
      • FAQ
    • Validators
      • Terms & Concepts
        • Validator, BLS key, Instance
          • Shard Assignment
        • Slots Bidding and Election
        • Effective Proof-of-Stake
        • Block Reward
        • Epoch Transition
        • Slashing
        • Undelegation
      • Server Setup
        • Requirements
        • Cloud Guides
          • Digital Ocean
          • Vultr
          • AWS
          • Google Cloud
        • Raspberry Pi Guide
      • Node Setup
        • 1. HMY CLI Download
        • 2. Setting up BLS Keys
        • 3. Syncing DB
        • 4. Installing & Updating
          • Installing A Node
            • Using Node Binary
            • (Deprecated) Using AutoNode
              • Install & Run
              • Update
              • Monitor
              • BLS Key Management
              • Collect Rewards
              • Maintenance
              • Troubleshoot
              • Extra
            • (deprecated) Using Node.sh
          • Upgrading A Node
            • Using Node Binary
            • Using AutoNode (deprecated)
            • Using Node.sh (deprecated)
          • Checking A Node
      • Creating A Validator
      • Managing A Validator
        • Checking Validator Information
        • Changing Validator Information
        • Delegating To A Validator
        • Undelegating From A Validator
        • Check Your Delegations
        • Collecting Rewards
        • Adding A Validator Logo
      • Staking Dashboard Basics
      • Validator Information Terms
      • Validator Security Tips
      • Slashing and Uptime
      • Monitoring
        • Node Sync
        • Prometheus & Grafana
        • Network Status
      • Troubleshooting
        • Why am i not Elected?
        • Frequently Asked Questions (FAQ)
      • Tools
        • Telegram Bots
        • Dashboards
        • Reward Calculators
        • Text User Interface (TUI)
        • HMY Bidder
        • Mobile Apps
          • One Validator Dashboard
          • Termux
    • Delegators
      • Introduction
      • Staking
        • Via Browser
          • Staking Dashboard
          • Staking Transactions
          • Sending Transactions
        • Via Mobile
        • FAQ
      • Redelegation
      • Informational Videos
Powered by GitBook
On this page
  • Overview
  • Video Tutorial
  • Setting up the Contract Metadata and Images using IPFS
  • Setting up the Remix Development Environment
  • Importing the contract
  • Compile the contract
  • Deploy the contract Locally
  • Interact with our Token
  • Deploy to a Harmony testnet
  • Viewing the NFT Token in Metamask
  • Next steps

Was this helpful?

Export as PDF
  1. Developers
  2. Tutorials

Deploying HRC721/NFT

This tutorial will take you through creating your own HRC721 or NFT. HRC721 is nothing but ERC721 deployed on Harmony.

PreviousDeploying HRC20NextThe Graph - Subgraphs

Last updated 3 years ago

Was this helpful?

Overview

In this tutorial we will create a non-fungible token (NFT) and deploy to harmony testnet.

HRC721 is a standard for representing ownership of, that is, where each token is unique such as in real estate or collectibles.

We will use contracts in to create an HRC721 and deploy using Remix.

Video Tutorial

Setting up the Contract Metadata and Images using IPFS

includes an optional metadata extension with a name, symbol and for each tokenID a tokenURI with can point to a JSON file with name, description and image for the given token ID.

For our example we will upload three files

  1. HarmonyLogo.svg which stores the Image used for the token.

  2. NFTTokenBaseURL.json which stores the metadata for all the tokens and is used when deploying the NFT contract.

  3. NFTToken0.json which stores an instance of the metadata for Token0.

Uploading to IPFS

We will use , a convenient IPFS API and toolkit, to store our NFT asset and metadata to ensure our NFT is truly decentralized. If you don't have a Pinata account, sign up for a free account and complete the steps to verify your email.

Once you've created an account:

  • Navigate to the "Pinata Upload" button on the top right

  • Upload an image to pinata - this will be the image asset for your NFT. Feel free to name the asset whatever you wish

  • After you upload, at the top of the page, there should be a green popup that allows you to view the hash of your upload —> Copy that hashcode. You can view your upload at: hash-code>

Feel free to change the data in the json files below. You can remove or add to the attributes section. Most importantly, make sure the image field points to the location of your IPFS image— otherwise, your NFT will include a photo of a (very cute!) Harmony Logo.

Once you're done editing the json file, save it and upload it to Pinata, following the same steps we did for uploading the image.

Here is the information for the two json files

Note that the image field uses the value from the Harmony Logo we uploaded above.

On your local machine

Make a new file called NFTTokenBaseURL.json and add the following json code:

[
    {
      "id": 0,
      "description": "My NFT",
      "external_url": "https://forum.openzeppelin.com/t/create-an-nft-and-deploy-to-a-public-testnet-using-truffle/2961",
      "image": "https://gateway.pinata.cloud/ipfs/QmTTg77eKPFeKF1h75KdRrC9pTRKiMb34J9uXGzfj5xq6r",
      "name": "My NFT 0"
    },
    {
      "id": 1,
      "description": "My NFT",
      "external_url": "https://forum.openzeppelin.com/t/create-an-nft-and-deploy-to-a-public-testnet-using-truffle/2961",
      "image": "https://gateway.pinata.cloud/ipfs/QmTTg77eKPFeKF1h75KdRrC9pTRKiMb34J9uXGzfj5xq6r",
      "name": "My NFT 1"
    },
    {
      "id": 2,
      "description": "My NFT",
      "external_url": "https://forum.openzeppelin.com/t/create-an-nft-and-deploy-to-a-public-testnet-using-truffle/2961",
      "image": "https://twemoji.maxcdn.com/svg/1f40e.svg",
      "name": "My NFT 2"
    }
  ]

Make a new file called NFTToken0.json and add the following json code:

{
    "id": 0,
    "description": "My NFT",
    "external_url": "https://forum.openzeppelin.com/t/create-an-nft-and-deploy-to-a-public-testnet-using-truffle/2961",
    "image": "https://gateway.pinata.cloud/ipfs/QmTTg77eKPFeKF1h75KdRrC9pTRKiMb34J9uXGzfj5xq6r",
    "name": "My NFT 0"
  }

For our example we loaded the following two files

Setting up the Remix Development Environment

If you haven’t used Remix before, you need to setup plugins so that you can use the Solidity Compiler and Deploy and Run Transactions.

Select the Plugin Manager button on the bottom left under the Environments heading. If the Solidity Compiler is not already active, search for it and then press the activate button.

Importing the contract

We need to import ERC721PresetMinterPauserAutoId into Remix.

In the new file add the import statement for ERC721PresetMinterPauserAutoId below.

We specify a minimum version of the Solidity compiler to use and import ERC721PresetMinterPauserAutoId from GitHub.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.0/contracts/presets/ERC721PresetMinterPauserAutoId.sol";

Note when importing the contract it automatically inserts the contracts under dependencies.

Compile the contract

Select the Solidity Compiler plugin on the left hand side of the screen. Press the Compile button to compile the contract.

The contract and the contracts it inherits from will be loaded into Remix. The contract will then be compiled.

Deploy the contract Locally

We can deploy our new token to a development blockchain. Providing a name, a symbol and a base URI as parameters to the constructor to create a new ERC721PresetMinterPauserAutoId.

Select the Deploy & Run Transactions plugin on the left hand side of the screen. Environment should default to JavaScript VM (Berlin) or JavasScript VM (London)our development blockchain. Change the gas limit to 5000000 Change the Contract to ERC721PresetMinterPauserAutoId

Press Deploy.

Remix will deploy our token . You can see the deployed contract under the Deployed contracts section. By pressing the drop down on the right you can see the methods which you can use to interact with the token.

Interact with our Token

Token metadata

We can call the contract functions to read token metadata such as name, symbol and baseURI

Press the name, symbol and baseURI function buttons and this will call the functions in our deployed token. Showing values:

  • baseURI: 0: string: https://my-json-server.typicode.com/abcoathup/samplenft/tokens/

  • name: 0: string: My Token

  • symbol: 0: string: My NFT

Mint

We can send a transaction to mint tokens to a given account, from an account with the minter role. In our case we are minting from the account which deployed the token, which is given the minter role.

We will mint 1 NFT with token ID 0 to our account: 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4

We can set the parameters as follows "0x5B38Da6a701c568545dCfcB03FcB875f56beddC4"

Press mint The transaction will be shown in the console

We can check the owner of the token and the token URI for the metadata Showing values:

  • ownerOf: 0: address: 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4

  • tokenURI: 0: string: https://my-json-server.typicode.com/abcoathup/samplenft/tokens/0

Deploy to a Harmony testnet

Setup and fund your Harmony Metamask Wallet

In order to deploy to Harmony Testnet you will need to setup Metamask and get some one tokens from the faucet.

After successful setup and funding your Metamask should look like this

Deploy to Harmony Testnet

Set the network in MetaMask to Harmony Testnet. Change the environment in Deploy and Run Transactions to Injected Web3 so that Remix uses web3 from MetaMask

Press Deploy. Confirm the transaction in MetaMask The console will show creation of ERC721PresetMinterPauserAutoId pending... and then shortly after the contract will be deployed.

Mint

We can send a transaction to mint tokens to a given account, from an account with the minter role.

In our case we are minting from the account which deployed the token, which is given the minter role.

We will mint 1 NFT with token ID 0. Specify the address that you want to be the token holder (0x8875fc2A47E35ACD1784bB5f58f563dFE86A8451 is one of my test accounts)

Press mint with the recipient address Confirm the transaction in MetaMask

The console will show transact to ERC721PresetMinterPauserAutoId.mint pending ... and then shortly afterwards the NFT will be minted

Viewing the NFT Token in Metamask

You can then add that token address to metamask,

Our NFT contract address is 0xe9218ef3c209e1e7db8bef2e33f822006b44bcd7

We add the NFT Token Contract

and after adding it to metamask we see

Next steps

  • Create your artwork and metadata.

  • Host your images and metadata in a location that will last the life of the token.

  • Define what rights your token holders have.

For the more visual learners, the steps above are summarized here:Now, we're going to want to upload one more document to Pinata. But before we do that, we need to create it!

HarmonyLogo.svg at

NFTTokenBaseURL.json at

NFTToken0.json at

Open in your favorite browser.

We are going to use Preset which is an ERC721 that is preset so it can be minted, paused and burned.

In the File Explorer press the to Create New File Call the new file OpenZeppelinPresetContracts.sol

Note: When importing via GitHub, you should specify the release tag, otherwise you will get the latest code in the master branch. For OpenZeppelin Contracts you should only use code published in an official release. We will import OpenZeppelin Contracts v3.4.0. (for further instructions on how imports work in remix see in the Remix documentation).

Specify the name, symbol and base URI to use for our new token. by selecting the drop down next to the deploy button. I am using “My NFT” and “NFT” and ""

We can interact with our deployed token using Remix. In the Deploy & Run Transactions plugin, under Deployed Contracts expand our deployed token (ERC721PRESETMINTERPAUSERAUTOID) to show the methods we can interact with. (for help see )

Harmony Metamask configuration instructions are .

Harmony Faucet Information is .

Check the gas limit is set to 5000000 Check the Contract is set to ERC721PresetMinterPauserAutoId Specify the name, symbol and base URI to use for our new token. I am using “My NFT” and “NFT” and “"

You will be able to see the contract deployed in metamask and the harmony explorer, for example is the contract I deployed.

By using the explorer and looking at your transaction history for your metamask account you can find the address of the NFT contract deployed. Our account is and our NFT contract is .

.

🏗️
➕
non-fungible tokens
Presets
OpenZeppelin Contracts
EIP-721
Pinata
here
https://gateway.pinata.cloud/ipfs/<
https://gateway.pinata.cloud/ipfs/QmTTg77eKPFeKF1h75KdRrC9pTRKiMb34J9uXGzfj5xq6r
https://gateway.pinata.cloud/ipfs/QmVkDbc6NPni1uzQq3gsiocUc3YGZjF7QGcM37hMcBqNmv
https://gateway.pinata.cloud/ipfs/QmdAprJQmTtZ3vQLuorpuwJwyXs4YyC8Uh11hjsevCM5DC
https://remix.ethereum.org/
ERC721PresetMinterPauserAutoId
Importing from GitHub 35
https://gateway.pinata.cloud/ipfs/QmTmHW5NDh5wUTstTLcPRkKgGU75tvapMhHtPxjcRtMkLN
Deployed Contracts in Remix documentation
here
here
https://gateway.pinata.cloud/ipfs/QmVkDbc6NPni1uzQq3gsiocUc3YGZjF7QGcM37hMcBqNmv
here
here
here
Prepare for mainnet 76
Add the Solidity Compiler Plugin
Presets Imported contracts
Select the Contract from the drop down
Enter the Parameters for My NFT
Deploy the contract locally
Methods for the Deployed Contract
Interacting with the deployed contract in Remix
Console showing the deployed Contract Transaction
Interacting with Token 0
Enter the Parameters for the NFT Contract
Confirm the contract deployment
Minting the Token
Confirmation of Minting
Add the NFT Token Contract address
NFT Token Contract in Metamask