To facilitate a marketplace on BizNet to pull in off-chain metadata for ERC721 assets, the NFT contract will need to return a URI where the metadata can be found. To find this URI, the token URI method in ERC721 and the URI method in ERC1155 are used to track your NFT. You should implement the function in the Contract:
The token URI function in your Contract should return an HTTP or IPFS URL. When queried, this URL should in turn return a JSON blob of data with the metadata for your token.
Marketplaces on BizNet support metadata that is structured according to the official ERC721 metadata standard. Additionally, several properties for your items are supported, giving you all the sorting and filtering capabilities on BizNet Marketplaces. The below metadata structure, allows the BizNet Marketplace to read and display the details about the assets which your NFTs represent.
Here's how each of these properties works:
To present NFT traits, include the following array in the metadata:
Here trait_type
is the name of the trait, value
is the value of the trait, and display_type
is a field indicating how you would like a numeric value should be displayed. For string traits, you don't have to worry about display_type
. All traits included in the attributes will be displayed in Attribute
. If you don't want to have a trait_type
for a particular trait, you can include just a value in the trait and it will be set as a generic attribute.
Numeric Traits
There are 3 supported options for display_type
: number
will show the value in pure number, boost_number
allows you to show the number with a Plus or Minus symbol, and boost_percentage
is similar to boost_number but will show a percent sign behind the number.
Date
The marketplace also supports date traits in date
display_type
. Pass in a UNIX timestamp as the value.
Property | Description |
---|---|
name
Name of the item. Max 200 characters.
description
A human-readable description of the item. Markdown is supported. Max 500 characters.
image
This is the URL to the image of the item. It can be just about any type of image. A 350 x 350 image is recommended.
animation_url
This is the URL to a multi-media attachment for the item. The file extensions GLTF, GLB, WEBM, MP4, M4V, OGV, and OGG are supported, along with the audio-only extensions MP3, WAV, and OGA.
animation_type
This is the file format of the multi-media attachment provided from animation_url.
external_url
This is the URL that will appear below the asset's image on the marketplace and will allow users to leave the marketplace and view the item on your site.
attributes
These are the attributes for the item to describe the detail of the NFT. (see array below)
This work is inspired by this blog
In this tutorial, we will create a non-fungible token (NFT) and deploy it to a public testnet.
ERC721 is a standard for representing ownership of non-fungible tokens, that is, where each token is unique such as in real estate or collectibles.
We will use Presets contracts in OpenZeppelin Contracts to create an ERC721 and deploy using Truffle.
We begin by creating a new project.
Then we install OpenZeppelin Contracts which has an implementation of ERC721.
Next, we install a development tool for deployment, for this tutorial we will use Truffle but we could use any other tools such as Builder, Remix, or OpenZeppelin CLI.
We will set up our Solidity project using truffle init
to create a contracts
directory and configuration to connect to a network.
We are going to use Preset ERC721PresetMinterPauserAutoId
which is an ERC721 that is preset so it can be minted (with auto token ID and metadata URI), paused, and burned.
The Preset contracts have already been compiled, so we only need to copy the artifacts to the build/contracts
directory.
Using your favorite editor create 2_deploy.js
in the migrations
directory with the following contents:
We will use truffle develop
to open a Truffle console with a development blockchain
Head over to https://faucet.bosagora.org/request/boa/your-address and request test BOA
We can deploy our new NFT to our development blockchain using migrate.
We can then use our deployed contract.
The accounts that we can use were displayed when we started truffle develop
We can call the contract to read token metadata such as name
, symbol
and baseURI
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.
We can check the owner of the token and the token URI for the metadata
EIP-721 2 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.
How you create and host this metadata is up to you. I would suggest using a domain that you control to point to where you host the data so that you can move it as required.
For this tutorial, we will use My JSON Server where we can store a single JSON file in a GitHub repository that we can access via a fake JSON server.
Warning For production we need to store our metadata in a permanent location that can exist for the life of the token.
A sample JSON for tokenID 1 is: http://my-json-server.typicode.com/huangsuyu/nft/tokens/1
Next we will deploy to Agora testnet .
To deploy, we will use the instructions for Connecting to Public Test Networks with Truffle
You will need the following:
RPC URL of TestNet
@truffle/hdwallet-provider
installed
Configure truffle-config.js
for TestNet
A funded testnet account and mnemonic
A secrets.json
or another secret-management solution. Make sure you don’t commit this to GitHub!
My truffle-config.js
has the following
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.
To see configured accounts run the command accounts
.
We will mint 1 NFT with token ID 1. Specify the address that you want to be the token holder (0xc7e4bBc4269fdC62F879834E363173aeE7895F45
is one of my test accounts)